Skip to content

Commit

Permalink
updated hourCycle-default.js to reflect new behaviour of hourCycle, w…
Browse files Browse the repository at this point in the history
…hich now associates h12 with h23 rather than h24. see tc39/ecma402#758.
  • Loading branch information
ben-allen authored and ptomato committed Oct 2, 2023
1 parent 63456ad commit 800d136
Showing 1 changed file with 26 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google Inc. All rights reserved.
// Copyright 2019 Google Inc., 2023 Igalia S.L. All rights reserved.
// This code is governed by the license found in the LICENSE file.

/*---
Expand All @@ -7,50 +7,37 @@ description: >
Intl.DateTimeFormat.prototype.resolvedOptions properly
reflect hourCycle settings.
info: |
12.4.5 Intl.DateTimeFormat.prototype.resolvedOptions()
11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions()
11.1.2 CreateDateTimeFormat ( dateTimeFormat, locales, options, required, defaults )
29. If dateTimeFormat.[[Hour]] is not undefined, then
a. Let hcDefault be dataLocaleData.[[hourCycle]].
b. Let hc be dateTimeFormat.[[HourCycle]].
c. If hc is null, then
i. Set hc to hcDefault.
d. If hour12 is not undefined, then
i. If hour12 is true, then
1. If hcDefault is "h11" or "h23", then
a. Set hc to "h11".
2. Else,
a. Set hc to "h12".
ii. Else,
1. Assert: hour12 is false.
2. If hcDefault is "h11" or "h23", then
a. Set hc to "h23".
3. Else,
a. Set hc to "h24".
e. Set dateTimeFormat.[[HourCycle]] to hc.
locale: [en, fr, it, ja, zh, ko, ar, hi]
23. Let dataLocaleData be localeData.[[<dataLocale>]].
24. If hour12 is true, then
a. Let hc be dataLocaleData.[[hourCycle12]].
25. Else if hour12 is false, then
a. Let hc be dataLocaleData.[[hourCycle24]].
26. Else,
a. Assert: hour12 is undefined.
b. Let hc be r.[[hc]].
c. If hc is null, set hc to dataLocaleData.[[hourCycle]].
27. Set dateTimeFormat.[[HourCycle]] to hc.
locale: [en, fr, it, ja, zh, ko, ar, hi, en-u-hc-h24]
---*/

let locales = ["en", "fr", "it", "ja", "zh", "ko", "ar", "hi"];

locales.forEach(function(locale) {
let hcDefault = (new Intl.DateTimeFormat(locale, {hour: "numeric"}))
.resolvedOptions().hourCycle;
if (hcDefault == "h11" || hcDefault == "h23") {
assert.sameValue("h11",
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: true}))
.resolvedOptions().hourCycle);
assert.sameValue("h23",
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: false}))
.resolvedOptions().hourCycle);
} else {
assert.sameValue(true, hcDefault == "h12" || hcDefault == "h24")
assert.sameValue("h12",
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: true}))
.resolvedOptions().hourCycle);
assert.sameValue("h24",
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: false}))
.resolvedOptions().hourCycle);
let hcDefault = new Intl.DateTimeFormat(locale, { hour: "numeric" }).resolvedOptions().hourCycle;
if (hcDefault === "h11" || hcDefault === "h12") {
assert.sameValue(new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true }).resolvedOptions().hourCycle, hcDefault);

// no locale has "h24" as a default. see https://github.com/tc39/ecma402/pull/758#issue-1622377292
assert.sameValue(new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: false }).resolvedOptions().hourCycle, "h23");
}
if (hcDefault === "h23" || hcDefault === "h24") {
assert.sameValue(new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: false }).resolvedOptions().hourCycle, hcDefault);

let hcHour12 = new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true }).resolvedOptions().hourCycle;
assert((hcHour12 === "h11" || hcHour12 === "h12"), "Expected `hourCycle` to be in ['h11', 'h12']");
}
});

0 comments on commit 800d136

Please sign in to comment.