Skip to content

Commit

Permalink
Only mutate date formatter if neccesary.
Browse files Browse the repository at this point in the history
  • Loading branch information
n0shake committed Mar 31, 2024
1 parent d05aba9 commit fc92609
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions Clocker/Overall App/DateFormatterManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
specializedFormatter.dateStyle = style
specializedFormatter.timeStyle = style
specializedFormatter.dateFormat = format
specializedFormatter.timeZone = TimeZone(identifier: timezoneIdentifier)
specializedFormatter.locale = locale
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
}

Expand Down

0 comments on commit fc92609

Please sign in to comment.