Open Bug 1749459 Opened 4 years ago Updated 2 years ago

Cannot set hourCycle with Services.intl.DateTimeFormat

Categories

(Core :: Internationalization, defect, P3)

defect

Tracking

()

Tracking Status
firefox98 --- affected

People

(Reporter: henry-x, Unassigned)

References

(Blocks 1 open bug)

Details

I'm working on thunderbird calendars, and I want to be able to display midnight as "24:00" (numerical end of the day) rather than "00:00" (numerical start of the day) in a locale-appropriate way. However, whilst I could do this with Intl.DateTimeFormat, I can't do so with the recommended Services.intl.DateTimeFormat.

Steps to Reproduce

formatter = new Services.intl.DateTimeFormat(undefined, { timeStyle: "short", hourCycle: "h24" })

Result

The given hourCycle value is ignored, and is set to h23 instead in the returned formatter object.

Expect

The given hourCycle to be used.

Origin?

I think the hourCycle value is ignored is because when timeStyle is given, the MozDateTimeFormat wrapper sets an explicit pattern (to "HH:mm" in my case) https://searchfox.org/mozilla-central/rev/b3933df6e119bd6caf5d9e5868670348ec26dee3/toolkit/components/mozintl/mozIntl.jsm#1031

Blocks: 1749011

The easy fix here would to not use the OS's pattern when an hour cycle is specified. The harder fix would be to swap out the hour cycle for patterns that have the same coarse hour cycle, and then fall back to the ICU patterns when the coarse hour cycle is different. It's doable, but I think we'll need to add

I'm not sure what the use case is for Thunderbird, but for this bug I would say we should do the easy thing of ignoring the OS preferences when the hour cycle is specified, and file a follow-up if we feel like we should do the harder version.

Severity: -- → S3
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.