When I use a standard NumberFormatter, it honors the formattingContext of .beginningOfSentence:
let formatter = NumberFormatter()
formatter.numberStyle = .spellOut
formatter.formattingContext = .beginningOfSentence
let string = formatter.string(for: 5) // "Five"; good
But when I try this with DateComponentsFormatter, it seems to ignore the formattingContext:
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .spellOut
formatter.formattingContext = .beginningOfSentence
let string = formatter.string(from: 5 * 60) // "five minutes"; bad, should be "Five minutes"
FWIW, I tried a variety of permutations, all to no avail:
Tested different locales to make sure it was not just a bug in a particular locale (e.g., I tried both English and French, it localizes correctly, but does not capitalize correctly);
Tested in macOS and various iOS versions (to make sure it was not unique to a particular platform/version);
Tried changing the order in which I set
unitsStyleandformattingContext;Tried explicitly setting
allowedUnitsandmaximumUnitCountin case it was getting confused by the potentially variable number of units/components represented by the string; andTried a variety of
formattingContextoptions (not just.beginningOfSentence) and they all just return the same lowercased string.
I have worked-around the immediate problem by just applying my own sentence capitalization to the string. But I just want to ensure I am not missing something obvious before I file a bug report. Looks like DateComponentsFormatter simply does not honor formattingContext.