Skip to content

Commit 7353744

Browse files
committed
updated hourCycle-default.js to reflect new behaviour of hourCycle, which now associates h12 with h23 rather than h24. see tc39/ecma402#758.
1 parent 9437cab commit 7353744

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js

+25-38
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,35 @@ description: >
99
info: |
1010
12.4.5 Intl.DateTimeFormat.prototype.resolvedOptions()
1111
12-
12.1.1 InitializeDateTimeFormat ( dateTimeFormat, locales, options )
13-
29. If dateTimeFormat.[[Hour]] is not undefined, then
14-
a. Let hcDefault be dataLocaleData.[[hourCycle]].
15-
b. Let hc be dateTimeFormat.[[HourCycle]].
16-
c. If hc is null, then
17-
i. Set hc to hcDefault.
18-
d. If hour12 is not undefined, then
19-
i. If hour12 is true, then
20-
1. If hcDefault is "h11" or "h23", then
21-
a. Set hc to "h11".
22-
2. Else,
23-
a. Set hc to "h12".
24-
ii. Else,
25-
1. Assert: hour12 is false.
26-
2. If hcDefault is "h11" or "h23", then
27-
a. Set hc to "h23".
28-
3. Else,
29-
a. Set hc to "h24".
30-
e. Set dateTimeFormat.[[HourCycle]] to hc.
31-
12+
12.1.1 InitializeDateTimeFormat ( dateTimeFormat, locales, options)
13+
23. Let dataLocaleData be localeData.[[<dataLocale>]].
14+
24. If hour12 is true, then
15+
a. Let hc be dataLocaleData.[[hourCycle12]].
16+
25. Else if hour12 is false, then
17+
a. Let hc be dataLocaleData.[[hourCycle24]].
18+
26. Else,
19+
a. Assert: hour12 is undefined.
20+
b. Let hc be r.[[hc]].
21+
c. If hc is null, set hc to dataLocaleData.[[hourCycle]].
22+
27. Set dateTimeFormat.[[HourCycle]] to hc.
23+
3224
locale: [en, fr, it, ja, zh, ko, ar, hi]
3325
---*/
3426

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

37-
locales.forEach(function(locale) {
38-
let hcDefault = (new Intl.DateTimeFormat(locale, {hour: "numeric"}))
39-
.resolvedOptions().hourCycle;
40-
if (hcDefault == "h11" || hcDefault == "h23") {
41-
assert.sameValue("h11",
42-
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: true}))
43-
.resolvedOptions().hourCycle);
44-
assert.sameValue("h23",
45-
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: false}))
46-
.resolvedOptions().hourCycle);
47-
} else {
48-
assert.sameValue(true, hcDefault == "h12" || hcDefault == "h24")
49-
assert.sameValue("h12",
50-
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: true}))
51-
.resolvedOptions().hourCycle);
52-
assert.sameValue("h24",
53-
(new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: false}))
54-
.resolvedOptions().hourCycle);
29+
locales.forEach(function(locale){
30+
let hcDefault = new Intl.DateTimeFormat(locale, {hour: "numeric"}).resolvedOptions().hourCycle;
31+
if (hcDefault === "h11" || hcDefault === "h12"){
32+
assert.sameValue(hcDefault, new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: true}).resolvedOptions().hourCycle);
33+
34+
// no locale has "h24" as a default. see https://github.com/tc39/ecma402/pull/758#issue-1622377292
35+
assert.sameValue("h23", new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: false}).resolvedOptions().hourCycle);
36+
}
37+
if (hcDefault === "h23" || hcDefault === "h24"){
38+
assert.sameValue(hcDefault, new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: false}).resolvedOptions().hourCycle);
39+
40+
let hcHour12 = new Intl.DateTimeFormat(locale, {hour: "numeric", hour12: true}).resolvedOptions().hourCycle;
41+
assert((hcHour12 === "h11" || hcHour12 === "h12"), "Expected `hourCycle` to be in ['h11', 'h12']");
5542
}
5643
});

0 commit comments

Comments
 (0)