Last active
November 25, 2016 16:01
-
-
Save portellaa/b05a3baec85db9e407f3ad726ba2d91b to your computer and use it in GitHub Desktop.
π©βοΈ example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension DateFormatter { | |
private enum DateFormatters { | |
static var yearMonthDayFormat: String = "yyyy%@MM%@dd" | |
static var dayMonthYearFormat: String = "dd%@MM%@yyyy" | |
static var chatDateFormat: String = "EEEE d'%@' MMMM" | |
static var yearMonthDayFormatters: [Separator : DateFormatter] = [:] | |
static var dayMonthYearFormatters: [Separator : DateFormatter] = [:] | |
static var dateFormatters: [String : DateFormatter] = [:] | |
static func dateFormatterWithFormat(format: String, separator: Separator) -> DateFormatter { | |
let formatter = DateFormatter() | |
formatter.dateFormat = String(format: format, separator, separator, separator) | |
return formatter | |
} | |
static func yearMonthDayFormatterWithSeparator(separator: Separator) -> DateFormatter { | |
if let formatter = yearMonthDayFormatters[separator] { | |
return formatter | |
} else { | |
let formatter = dateFormatterWithFormat(yearMonthDayFormat, separator: separator) | |
yearMonthDayFormatters[separator] = formatter | |
return formatter | |
} | |
} | |
} | |
static func yearMonthDayFormatter(separator: Separator) -> DateFormatter { | |
return DateFormatters.yearMonthDayFormatterWithSeparator(separator) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment