Closed Bug 1645115 Opened 1 year ago Closed 4 months ago

Enable dayPeriod support in Intl.DateTimeFormat

Categories

(Core :: JavaScript: Internationalization API, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
90 Branch
Tracking Status
firefox90 --- fixed

People

(Reporter: Waldo, Assigned: anba)

References

Details

(Keywords: dev-doc-complete)

Attachments

(3 files)

We support dayPeriod in date-time formatting now only in nightly, because of ICU/CLDR issues. Some of those were fixed by the update to 67. It looks like bug 1636984's concerns are the only remaining issues to fix still before we do this.

Filing a fresh bug for PR tracking purposes...

Looks like bug 1636984 is fixed now.

There are still some open review issues in the spec PR, though.

Severity: -- → N/A
Priority: -- → P3

"dayPeriod" support was added in bug 1569103, this patch just enables it by default.

Assignee: nobody → andrebargull
Status: NEW → ASSIGNED

These features have shipped, so we can remove the "release_or_beta" flags.

Depends on D115608

Pushed by andre.bargull@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/ba69a44bcef5
Part 1: Enable "dayPeriod" by default. r=mgaudet
https://hg.mozilla.org/integration/autoland/rev/43f5e887e19a
Part 2: Remove some old "release_or_beta" flags. r=mgaudet
https://hg.mozilla.org/integration/autoland/rev/0a003fecf98d
Part 3: Enable test262 dayPeriod tests by default. r=mgaudet
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 90 Branch

Firefox 90 docs work for this can be tracked in: https://github.com/mdn/content/issues/5382

I tested the existing docs in Firefox 91 using this code:

var date = Date.UTC(2012, 11, 17, 20, 0, 42);
console.log(new Intl.DateTimeFormat('en-GB', { dayPeriod: 'narrow' }).format(date));
console.log(new Intl.DateTimeFormat('en-GB', { dayPeriod: 'short' }).format(date));
console.log(new Intl.DateTimeFormat('en-GB', { dayPeriod: 'long' }).format(date));

All three lines output "in the morning". If I change the time I can get "in the afternoon".

Shouldn't narrow, short and long options emit something different?

The docs indicate: "AM", "PM", "in the morning", or "noon" but would be good to understand whether I'm using this wrong, and how you would get the other options.

Flags: needinfo?(andrebargull)

The CLDR sources for English don't provide any abbreviations. It looks like the data for French (among others) has abbreviated names:

js> var date = Date.UTC(2012, 11, 17, 16, 0, 42);
js> console.log(new Intl.DateTimeFormat('fr', { dayPeriod: 'narrow', timeZone: 'UTC' }).format(date));
ap.m.
js> console.log(new Intl.DateTimeFormat('fr', { dayPeriod: 'short', timeZone: 'UTC' }).format(date));
ap.m.
js> console.log(new Intl.DateTimeFormat('fr', { dayPeriod: 'long', timeZone: 'UTC' }).format(date));
de l’après-midi

It seems like UTS even states that for many locales "[...] there is only one width that is customarily used".


For MDN it's probably also worth noting that dayPeriod (unless used in stand-alone contexts) only has an effect if a 12-hour clock is used. For example:

js> console.log(new Intl.DateTimeFormat('fr', { hour: 'numeric', dayPeriod: 'long', timeZone: 'UTC' }).format(date));
16 h
js> console.log(new Intl.DateTimeFormat('fr', { hour: 'numeric', hourCycle: 'h12', dayPeriod: 'long', timeZone: 'UTC' }).format(date));
4 de l’après-midi

HTH,
André

Flags: needinfo?(andrebargull)

Thanks very much Andre - yes it does help a lot.

FYI, all pending review but:

I will add dev-docs-complete too.

You need to log in before you can comment on or make changes to this bug.