From 2a97a389c1fcf43929605cf6d88ae44f70fdbe06 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Tue, 25 Jul 2023 15:51:11 -0700 Subject: [PATCH 1/3] 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. --- .../resolvedOptions/hourCycle-default.js | 65 ++++++++----------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js b/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js index 7b82422cfd7..8b1e71f905d 100644 --- a/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js +++ b/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js @@ -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. /*--- @@ -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.[[]]. + 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']"); } }); From f92c2ac656ddd51e3db34d11d2a570fdaec31c62 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Wed, 26 Jul 2023 17:12:16 -0700 Subject: [PATCH 2/3] corrected hourCycle-default.js to handle language tags with -u-hc-h24 extension --- .../prototype/resolvedOptions/hourCycle-default.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js b/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js index 8b1e71f905d..2d8a38e7042 100644 --- a/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js +++ b/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-default.js @@ -24,7 +24,7 @@ info: | locale: [en, fr, it, ja, zh, ko, ar, hi, en-u-hc-h24] ---*/ -let locales = ["en", "fr", "it", "ja", "zh", "ko", "ar", "hi"]; +let locales = ["en", "fr", "it", "ja", "ja-u-hc-h11", "zh", "ko", "ar", "hi", "en-u-hc-h24"]; locales.forEach(function(locale) { let hcDefault = new Intl.DateTimeFormat(locale, { hour: "numeric" }).resolvedOptions().hourCycle; @@ -34,10 +34,12 @@ locales.forEach(function(locale) { // 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"); } + + // however, "h24" can be set via locale extension. 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']"); } + + let hcHour12 = new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true }).resolvedOptions().hourCycle; + assert(hcHour12 === "h11" || hcHour12 === "h12", "Expected `hourCycle`: " + hcHour12 + " to be in [\"h11\", \"h12\"]"); }); From 393078b7a5fdb71b376ba85b044482f6235e438a Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Thu, 27 Jul 2023 05:34:44 -0700 Subject: [PATCH 3/3] added clarifying comments on hourCycle-dateStyle.js --- .../resolvedOptions/hourCycle-dateStyle.js | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-dateStyle.js b/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-dateStyle.js index 7faef9646ff..fc46620f3bd 100644 --- a/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-dateStyle.js +++ b/test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-dateStyle.js @@ -6,6 +6,30 @@ esid: sec-Intl.DateTimeFormat.prototype.resolvedOptions description: > Intl.DateTimeFormat.prototype.resolvedOptions properly reflect hourCycle settings when using dateStyle. + Note: "properly reflect hourCycle settings when using dateStyle", in this context, means "if dateStyle but not timeStyle is set, both hourCycle and hour12 will be *undefined*". This is because the CreateDateTimeFormat AO resets [[HourCycle]] to *undefined* if [[Hour]] is *undefined*, and if dateStyle but not timeStyle is set, [[HourCycle]] is set to *undefined*. +info: | + 11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions() + ... + 5. For each row of Table 6, except the header row, in table order, do + a. Let p be the Property value of the current row. + b. If p is "hour12", then + i. Let hc be dtf.[[HourCycle]]. + ii. If hc is "h11" or "h12", let v be true. + iii. Else if, hc is "h23" or "h24", let v be false. + iv. Else, let v be undefined. + c. Else, + i. Let v be the value of dtf's internal slot whose name is the Internal Slot value of the current row. + d. If the Internal Slot value of the current row is an Internal Slot value in Table 7, then + i. If dtf.[[DateStyle]] is not undefined or dtf.[[TimeStyle]] is not undefined, then + 1. Let v be undefined. + e. If v is not undefined, then + i. Perform ! CreateDataPropertyOrThrow(options, p, v). + + 11.1.2 CreateDateTimeFormat( newTarget, locales, options, required, defaults) + ... + 45. If dateTimeFormat.[[Hour]] is undefined, then + + a. Set dateTimeFormat.[[HourCycle]] to undefined. features: [Intl.DateTimeFormat-datetimestyle] ---*/ @@ -17,7 +41,7 @@ for (const dateStyle of ["full", "long", "medium", "short"]) { dateStyle, `Should support dateStyle=${dateStyle}`); - /* Values passed via unicode extension key work */ + /* Values passed via unicode extension key set to *undefined* */ for (const hcValue of hcValues) { const resolvedOptions = new Intl.DateTimeFormat(`de-u-hc-${hcValue}`, { @@ -28,7 +52,7 @@ for (const dateStyle of ["full", "long", "medium", "short"]) { assert.sameValue(resolvedOptions.hour12, undefined); } - /* Values passed via options work */ + /* Values passed via options set to *undefined**/ for (const hcValue of hcValues) { const resolvedOptions = new Intl.DateTimeFormat("en-US", {