Browse Source

Only mutate date formatter if neccesary.

master
Abhishek Banthia 7 months ago
parent
commit
fc92609c9e
  1. 22
      Clocker/Overall App/DateFormatterManager.swift

22
Clocker/Overall App/DateFormatterManager.swift

@ -20,12 +20,32 @@ class DateFormatterManager: NSObject {
return dateFormatter
}
class func dateFormatterWithFormat(with style: DateFormatter.Style, format: String, timezoneIdentifier: String, locale: Locale = Locale(identifier: "en_US")) -> DateFormatter {
class func dateFormatterWithFormat(with style: DateFormatter.Style,
format: String,
timezoneIdentifier: String,
locale:
Locale = Locale(identifier: "en_US")) -> DateFormatter {
if (specializedFormatter.dateStyle != style) {
specializedFormatter.dateStyle = style
}
if (specializedFormatter.timeStyle != style) {
specializedFormatter.timeStyle = style
}
if (specializedFormatter.dateFormat != format) {
specializedFormatter.dateFormat = format
}
if (specializedFormatter.timeZone.identifier != timezoneIdentifier) {
specializedFormatter.timeZone = TimeZone(identifier: timezoneIdentifier)
}
if (specializedFormatter.locale.identifier != locale.identifier) {
specializedFormatter.locale = locale
}
return specializedFormatter
}

Loading…
Cancel
Save