updated hourCycle-default.js to reflect new behaviour of hourCycle, which now associates h12 with h23 rather than h24. see https://github.com/tc39/ecma402/pull/758.

This commit is contained in:
Ben Allen 2023-07-25 15:51:11 -07:00 committed by Philip Chimento
parent 63456adb38
commit 800d136d96

View File

@ -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. // This code is governed by the license found in the LICENSE file.
/*--- /*---
@ -7,50 +7,37 @@ description: >
Intl.DateTimeFormat.prototype.resolvedOptions properly Intl.DateTimeFormat.prototype.resolvedOptions properly
reflect hourCycle settings. reflect hourCycle settings.
info: | info: |
12.4.5 Intl.DateTimeFormat.prototype.resolvedOptions() 11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions()
11.1.2 CreateDateTimeFormat ( dateTimeFormat, locales, options, required, defaults ) 11.1.2 CreateDateTimeFormat ( dateTimeFormat, locales, options, required, defaults )
29. If dateTimeFormat.[[Hour]] is not undefined, then 23. Let dataLocaleData be localeData.[[<dataLocale>]].
a. Let hcDefault be dataLocaleData.[[hourCycle]]. 24. If hour12 is true, then
b. Let hc be dateTimeFormat.[[HourCycle]]. a. Let hc be dataLocaleData.[[hourCycle12]].
c. If hc is null, then 25. Else if hour12 is false, then
i. Set hc to hcDefault. a. Let hc be dataLocaleData.[[hourCycle24]].
d. If hour12 is not undefined, then 26. Else,
i. If hour12 is true, then a. Assert: hour12 is undefined.
1. If hcDefault is "h11" or "h23", then b. Let hc be r.[[hc]].
a. Set hc to "h11". c. If hc is null, set hc to dataLocaleData.[[hourCycle]].
2. Else, 27. Set dateTimeFormat.[[HourCycle]] to hc.
a. Set hc to "h12".
ii. Else, locale: [en, fr, it, ja, zh, ko, ar, hi, en-u-hc-h24]
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]
---*/ ---*/
let locales = ["en", "fr", "it", "ja", "zh", "ko", "ar", "hi"]; let locales = ["en", "fr", "it", "ja", "zh", "ko", "ar", "hi"];
locales.forEach(function(locale) { locales.forEach(function(locale) {
let hcDefault = (new Intl.DateTimeFormat(locale, {hour: "numeric"})) let hcDefault = new Intl.DateTimeFormat(locale, { hour: "numeric" }).resolvedOptions().hourCycle;
.resolvedOptions().hourCycle; if (hcDefault === "h11" || hcDefault === "h12") {
if (hcDefault == "h11" || hcDefault == "h23") { assert.sameValue(new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true }).resolvedOptions().hourCycle, hcDefault);
assert.sameValue("h11",
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: true})) // no locale has "h24" as a default. see https://github.com/tc39/ecma402/pull/758#issue-1622377292
.resolvedOptions().hourCycle); assert.sameValue(new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: false }).resolvedOptions().hourCycle, "h23");
assert.sameValue("h23", }
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: false})) if (hcDefault === "h23" || hcDefault === "h24") {
.resolvedOptions().hourCycle); assert.sameValue(new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: false }).resolvedOptions().hourCycle, hcDefault);
} else {
assert.sameValue(true, hcDefault == "h12" || hcDefault == "h24") let hcHour12 = new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true }).resolvedOptions().hourCycle;
assert.sameValue("h12", assert((hcHour12 === "h11" || hcHour12 === "h12"), "Expected `hourCycle` to be in ['h11', 'h12']");
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: true}))
.resolvedOptions().hourCycle);
assert.sameValue("h24",
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: false}))
.resolvedOptions().hourCycle);
} }
}); });