You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

48 lines
2.2 KiB

// Copyright © 2015 Abhishek Banthia
import Cocoa
class DateFormatterManager: NSObject {
private static var dateFormatter = DateFormatter()
private static var calendarDateFormatter = DateFormatter()
private static var simpleFormatter = DateFormatter()
private static var specializedFormatter = DateFormatter()
private static var localizedForamtter = DateFormatter()
private static var localizedSimpleFormatter = DateFormatter()
private static var gregorianCalendar = Calendar(identifier: Calendar.Identifier.gregorian)
private static var USLocale = Locale(identifier: "en_US")
class func dateFormatter(with style: DateFormatter.Style, for timezoneIdentifier: String) -> DateFormatter {
dateFormatter.dateStyle = style
dateFormatter.timeStyle = style
dateFormatter.locale = USLocale
dateFormatter.timeZone = TimeZone(identifier: timezoneIdentifier)
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
return specializedFormatter
}
class func localizedFormatter(with format: String, for timezoneIdentifier: String, locale _: Locale = Locale.autoupdatingCurrent) -> DateFormatter {
dateFormatter.dateStyle = .none
dateFormatter.timeStyle = .none
dateFormatter.locale = Locale.autoupdatingCurrent
dateFormatter.dateFormat = format
dateFormatter.timeZone = TimeZone(identifier: timezoneIdentifier)
return dateFormatter
}
class func localizedSimpleFormatter(_ format: String) -> DateFormatter {
localizedSimpleFormatter.dateStyle = .none
localizedSimpleFormatter.timeStyle = .none
localizedSimpleFormatter.dateFormat = format
localizedSimpleFormatter.locale = Locale.autoupdatingCurrent
return localizedSimpleFormatter
}
}