Skip to content

Instantly share code, notes, and snippets.

@kumo
Last active June 29, 2022 16:29
Show Gist options
  • Save kumo/5f32b611db3c3b4f944f to your computer and use it in GitHub Desktop.
Save kumo/5f32b611db3c3b4f944f to your computer and use it in GitHub Desktop.
Checking the date order of the current locale
extension Locale {
enum DateOrder {
case DayFirst, MonthFirst, YearFirst
}
func dateOrder() -> DateOrder {
guard let formatter = DateFormatter.dateFormat(fromTemplate: "MMMMdY", options: 0, locale: self) else {
return .DayFirst
}
if formatter.hasPrefix("Y") {
return .YearFirst
}
if formatter.hasPrefix("M") {
return .MonthFirst
}
return .DayFirst
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment