Rob
Rob

Reputation: 437432

DateComponentsFormatter not honoring formattingContext

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:

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.

Upvotes: 4

Views: 166

Answers (0)

Related Questions