Sounds like something that should be in the WatchOS framework
Well, you what what to do (-:
Two things:
If you do file a enhancement request, please post your bug number, just for the record.
Give some thought about what you want to request. For example, would you prefer to have a date picker, à la iOS, or better APIs at the ‘model’ layer? Remember that it’s OK to file more than one enhancement request for any given issue!
I guess I don't understand calendars and locale well enough to comprehend your hints/suggestions.
Fair enough. You’ve posted code with lots of different options, so it’s hard to nail things down one specific test case. What I was expecting you’d do is:
get the user’s current locale (
+currentLocale
)get its locale identifier (
localeIdentifier
)bring it into components (
+componentsFromLocaleIdentifier:
)modify the components force Gregorian
build a new locale identifier (
+localeIdentifierFromComponents:
)create a locale from that (
+localeWithLocaleIdentifier:
)use that to create your date format from a template (
+dateFormatFromTemplate:options:locale:
)
That is, you want to honour the user’s locale settings except that you want to override the calendar to Gregorian.
Now, with the abbreviated month (
MMM
) it’s not obvious that you’ll see date reversals (“Oct 30” vs “30 Oct”) in common locales. However, a quick test reveals a
wide variety of results. Put this code in a small command line tool and run it on your Mac:
import Foundation
for locID in NSLocale.availableLocaleIdentifiers() {
let loc = NSLocale(localeIdentifier: locID)
let dfs = NSDateFormatter.dateFormatFromTemplate("MMM d", options: 0, locale: loc)!
NSLog("%@ %@", locID, dfs)
}
Look through this output carefully because it reveals some edge cases with the parsing. For example, both Japanese and Chinese locales return the string “M月d日”, indicating numeric months and days with non-numeric markers. Which brings me back to my original comment, that this is trickier than you might think, and also explains why there’s no simplistic “what’s the day-month-year order” API.
Share and Enjoy
—
Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"