Browse Source

Only mutate date formatter if neccesary.

master
Abhishek Banthia 9 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 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 specializedFormatter.dateStyle = style
}
if (specializedFormatter.timeStyle != style) {
specializedFormatter.timeStyle = style specializedFormatter.timeStyle = style
}
if (specializedFormatter.dateFormat != format) {
specializedFormatter.dateFormat = format specializedFormatter.dateFormat = format
}
if (specializedFormatter.timeZone.identifier != timezoneIdentifier) {
specializedFormatter.timeZone = TimeZone(identifier: timezoneIdentifier) specializedFormatter.timeZone = TimeZone(identifier: timezoneIdentifier)
}
if (specializedFormatter.locale.identifier != locale.identifier) {
specializedFormatter.locale = locale specializedFormatter.locale = locale
}
return specializedFormatter return specializedFormatter
} }

Loading…
Cancel
Save