From 5a3134022f0dc8124994983d20bdb267b47da495 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Mon, 7 Aug 2023 16:57:54 -0700 Subject: [PATCH 1/4] two new tests for fractionalDigits --- ...tyle-digital-fractionalDigits-undefined.js | 56 +++++++++++++++++++ .../format/style-digital-fractionalDigits.js | 40 +++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js create mode 100644 test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js diff --git a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js new file mode 100644 index 00000000000..9a8bc5bc10e --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js @@ -0,0 +1,56 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-partitiondurationformatpattern +description: > + Test to ensure that correct number of fractional digits is displayed (i.e. however many are necessary to represent the data fully) if the fractionalDigits option is left *undefined* + +info: | + 4. If durationFormat.[[FractionalDigits]] is undefined, then + a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", 9). + b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", 0). + 5. Else, + a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", durationFormat.[[FractionalDigits]]). + b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", durationFormat.[[FractionalDigits]]). + +---*/ + + +const durationNano = { + hours: 1, + minutes: 22, + seconds: 33, + milliseconds: 111, + microseconds: 222, + nanoseconds: 333 +}; + +const durationMicro = { + hours: 1, + minutes: 22, + seconds: 33, + milliseconds: 111, + microseconds: 222 +}; + +const durationMill = { + hours: 1, + minutes: 22, + seconds: 33, + milliseconds: 111 +} + +const durationNoSubsecond = { + hours: 1, + minutes: 22, + seconds: 33 +} + +const style = "digital"; +const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: undefined}); + +assert.sameValue(df.format(durationNano), "1:22:33.111222333", `format output with nanosecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationMicro), "1:22:33.111222", `format output with microsecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationMilli), "1:22:33.111", `format output with millisecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationNoSubsecond), "1:22:33", `format output with no subsecond digits and fractionalDigits: undefined using ${style} style option`); diff --git a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js new file mode 100644 index 00000000000..ea816c1bf7b --- /dev/null +++ b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-partitiondurationformatpattern +description: > + Test to ensure that correct number of fractional digits is displayed if fractionalDigits is explicitly specified. + +info: | + 4. If durationFormat.[[FractionalDigits]] is undefined, then + a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", 9). + b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", 0). + 5. Else, + a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", durationFormat.[[FractionalDigits]]). + b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", durationFormat.[[FractionalDigits]]). +---*/ + +const duration = { + hours: 1, + minutes: 22, + seconds: 33, + milliseconds: 111, + microseconds: 222, + nanoseconds: 333, +}; + + +const style = "digital"; +const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: 0}); +const dfMilli = new Intl.DurationFormat(undefined, {style, fractionalDigits: 3}); +const dfMicro = new Intl.DurationFormat(undefined, {style, fractionalDigits: 6}); +const dfNano = new Intl.DurationFormat(undefined, {style, fractionalDigits: 9}); + +assert.sameValue(df.format(duration), "1:22:33", `format output without sub-second digits using ${style} style option`); + +assert.sameValue(dfMilli.format(duration), "1:22:33.111", `format output with sub-second digits and fractionalDigits: 3 using ${style} style option`); + +assert.sameValue(dfMicro.format(duration), "1:22:33.111222", `format output with sub-second digits and fractionalDigits: 6 using ${style} style option`); + +assert.sameValue(dfNano.format(duration), "1:22:33.111222333", `format output with sub-second digits and fractionalDigits: 9 using ${style} style option`); From f5d1398f2c8b5c0b8fe45c4f26809290a5ba9823 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Mon, 7 Aug 2023 18:46:01 -0700 Subject: [PATCH 2/4] updated constructor options test to reflect undefined as valid value --- .../constructor-options-fractionalDigits-valid.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/intl402/DurationFormat/constructor-options-fractionalDigits-valid.js b/test/intl402/DurationFormat/constructor-options-fractionalDigits-valid.js index a9ece06bed5..87109c7e9f5 100644 --- a/test/intl402/DurationFormat/constructor-options-fractionalDigits-valid.js +++ b/test/intl402/DurationFormat/constructor-options-fractionalDigits-valid.js @@ -15,7 +15,8 @@ const validOptions = [ 0, 1, 5, - 9 + 9, + undefined ]; for (const fractionalDigits of validOptions) { From a7aad3da5d847d081aa934a4500aaaad028ef168 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Mon, 7 Aug 2023 23:47:24 -0700 Subject: [PATCH 3/4] fixed (C) year in metadata --- .../format/style-digital-fractionalDigits-undefined.js | 2 +- .../prototype/format/style-digital-fractionalDigits.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js index 9a8bc5bc10e..d68c4838bf1 100644 --- a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js +++ b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// Copyright (C) 2023 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- diff --git a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js index ea816c1bf7b..d6e68f5b107 100644 --- a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js +++ b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// Copyright (C) 2023 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- From a32984435fbec954c88c9a47c8eaff7f4c613405 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Tue, 8 Aug 2023 06:10:19 -0700 Subject: [PATCH 4/4] added additional tests for numbers of digits that aren't multiples of 3 --- .../style-digital-fractionalDigits-undefined.js | 16 ++++++++++++++-- .../format/style-digital-fractionalDigits.js | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js index d68c4838bf1..8dfb06a7fd8 100644 --- a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js +++ b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits-undefined.js @@ -39,13 +39,22 @@ const durationMill = { minutes: 22, seconds: 33, milliseconds: 111 -} +}; const durationNoSubsecond = { hours: 1, minutes: 22, seconds: 33 -} +}; + +const durationSevenFractional = { + hours: 2, + minutes: 30, + seconds: 10, + milliseconds: 111, + microseconds: 220, + nanoseconds: 300 +}; const style = "digital"; const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: undefined}); @@ -54,3 +63,6 @@ assert.sameValue(df.format(durationNano), "1:22:33.111222333", `format output wi assert.sameValue(df.format(durationMicro), "1:22:33.111222", `format output with microsecond digits and fractionalDigits: undefined using ${style} style option`); assert.sameValue(df.format(durationMilli), "1:22:33.111", `format output with millisecond digits and fractionalDigits: undefined using ${style} style option`); assert.sameValue(df.format(durationNoSubsecond), "1:22:33", `format output with no subsecond digits and fractionalDigits: undefined using ${style} style option`); + +assert.sameValue(df.format(durationFiveFractional), "2:30:11122", `format output with five subsecond digits and fractionalDigits: undefined using ${style} style option`); +assert.sameValue(df.format(durationSevenFractional), "2:30:1112203", `format output with seven subsecond digits and fractionalDigits: undefined using ${style} style option`); diff --git a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js index d6e68f5b107..36a3baf2ead 100644 --- a/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js +++ b/test/intl402/DurationFormat/prototype/format/style-digital-fractionalDigits.js @@ -28,13 +28,19 @@ const duration = { const style = "digital"; const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: 0}); const dfMilli = new Intl.DurationFormat(undefined, {style, fractionalDigits: 3}); +const dfFourDigits = new Intl.DurationFormat(undefined, {style, fractionalDigits: 4}); const dfMicro = new Intl.DurationFormat(undefined, {style, fractionalDigits: 6}); +const dfEightDigits = new Intl.DurationFormat(undefined, {style, fractionalDigits: 8}); const dfNano = new Intl.DurationFormat(undefined, {style, fractionalDigits: 9}); assert.sameValue(df.format(duration), "1:22:33", `format output without sub-second digits using ${style} style option`); assert.sameValue(dfMilli.format(duration), "1:22:33.111", `format output with sub-second digits and fractionalDigits: 3 using ${style} style option`); +assert.sameValue(dfFourDigits.format(duration), "1:22:33.1112", `format output with sub-second digits and fractionalDigits: 4 using ${style} style option`); + assert.sameValue(dfMicro.format(duration), "1:22:33.111222", `format output with sub-second digits and fractionalDigits: 6 using ${style} style option`); +assert.sameValue(dfEightDigits.format(duration), "1:22:33.11122233", `format output with sub-second digits and fractionalDigits: 8 using ${style} style option`); + assert.sameValue(dfNano.format(duration), "1:22:33.111222333", `format output with sub-second digits and fractionalDigits: 9 using ${style} style option`);