From ccf8977b1c101b77aa80c5f16e18b12c8d8303ba Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 29 Oct 2024 17:23:37 -0700 Subject: [PATCH] Temporal: Split up ZonedDateTime/old/string-parsing.js and move out of staging --- ...gument-string-basic-and-extended-format.js | 28 ++++++++ .../from/argument-string-decimal-places.js | 37 ++++++++++ .../argument-string-negative-extended-year.js | 13 ++++ .../from/argument-string-no-junk-at-end.js | 11 +++ .../from/argument-string-optional-parts.js | 19 ++++++ ...gument-string-variant-decimal-separator.js | 13 ++++ .../ZonedDateTime/from/bad-disambiguation.js | 16 +++++ ...ain-has-no-effect-on-invalid-iso-string.js | 10 +++ .../offset-does-not-match-iana-time-zone.js | 2 + .../ZonedDateTime/old/string-parsing.js | 67 ------------------- 10 files changed, 149 insertions(+), 67 deletions(-) create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-string-basic-and-extended-format.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-string-decimal-places.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-string-negative-extended-year.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-string-no-junk-at-end.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-string-optional-parts.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-string-variant-decimal-separator.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/bad-disambiguation.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/constrain-has-no-effect-on-invalid-iso-string.js delete mode 100644 test/staging/Temporal/ZonedDateTime/old/string-parsing.js diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-string-basic-and-extended-format.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-basic-and-extended-format.js new file mode 100644 index 0000000000..e172d19101 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-basic-and-extended-format.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Mixture of basic and extended format. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +[ + "1976-11-18T152330.1-08:00[-08:00]", + "19761118T15:23:30.1-08:00[-08:00]", + "1976-11-18T15:23:30.1-0800[-08:00]", + "1976-11-18T152330.1-0800[-08:00]", + "19761118T15:23:30.1-0800[-08:00]", + "19761118T152330.1-08:00[-08:00]", + "19761118T152330.1-0800[-08:00]", + "+001976-11-18T152330.1-08:00[-08:00]", + "+0019761118T15:23:30.1-08:00[-08:00]", + "+001976-11-18T15:23:30.1-0800[-08:00]", + "+001976-11-18T152330.1-0800[-08:00]", + "+0019761118T15:23:30.1-0800[-08:00]", + "+0019761118T152330.1-08:00[-08:00]", + "+0019761118T152330.1-0800[-08:00]" +].forEach(input => TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from(input), + new Temporal.ZonedDateTime(217207410100000000n, "-08:00"))); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-string-decimal-places.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-decimal-places.js new file mode 100644 index 0000000000..17a30746ad --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-decimal-places.js @@ -0,0 +1,37 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: from() can parse any number of decimal places +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410100000000n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410120000000n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410123000000n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1234-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410123400000n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12345-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410123450000n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410123456000n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1234567-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410123456700n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12345678-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410123456780n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410123456789n, "-08:00")); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-string-negative-extended-year.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-negative-extended-year.js new file mode 100644 index 0000000000..ff924f6922 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-negative-extended-year.js @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Can parse negative extended year +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("-009999-11-18T15:23:30.12+00:00[UTC]"), + new Temporal.ZonedDateTime(-377677326989880000000n, "UTC")); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-string-no-junk-at-end.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-no-junk-at-end.js new file mode 100644 index 0000000000..da78404bc0 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-no-junk-at-end.js @@ -0,0 +1,11 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: No junk at end of string. +features: [Temporal] +---*/ + +assert.throws(RangeError, () => Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-08:00[-08:00]junk")) + diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-string-optional-parts.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-optional-parts.js new file mode 100644 index 0000000000..86eb5bb46c --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-optional-parts.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Optional parts. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30-08[-08:00]"), + new Temporal.ZonedDateTime(217207410000000000n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15-08:00[-08:00]"), + new Temporal.ZonedDateTime(217206000000000000n, "-08:00")); +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("2020-01-01[+09:00]"), + new Temporal.ZonedDateTime(1577804400000000000n, "+09:00")); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-string-variant-decimal-separator.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-variant-decimal-separator.js new file mode 100644 index 0000000000..9de7136c61 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-variant-decimal-separator.js @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Can parse variant decimal separator. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +TemporalHelpers.assertZonedDateTimesEqual( + Temporal.ZonedDateTime.from("1976-11-18T15:23:30,12-08:00[-08:00]"), + new Temporal.ZonedDateTime(217207410120000000n, "-08:00")); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/bad-disambiguation.js b/test/built-ins/Temporal/ZonedDateTime/from/bad-disambiguation.js new file mode 100644 index 0000000000..e33ae43322 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/bad-disambiguation.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Throw on bad value for disambiguation +features: [Temporal] +---*/ + +[ + "", + "EARLIER", + "balance" +].forEach(disambiguation => { + assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-11-01T04:00[-08:00]", { disambiguation })); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/constrain-has-no-effect-on-invalid-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/from/constrain-has-no-effect-on-invalid-iso-string.js new file mode 100644 index 0000000000..447b3b0c7a --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/constrain-has-no-effect-on-invalid-iso-string.js @@ -0,0 +1,10 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Constrain overflow option has no effect on invalid ISO string. +features: [Temporal] +---*/ + +assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-13-34T24:60[-08:00]", { overflow: "constrain" })); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/offset-does-not-match-iana-time-zone.js b/test/built-ins/Temporal/ZonedDateTime/from/offset-does-not-match-iana-time-zone.js index 6b3e34fbdc..b303b7747e 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/offset-does-not-match-iana-time-zone.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/offset-does-not-match-iana-time-zone.js @@ -18,3 +18,5 @@ const obj = { assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj)); assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" })); +assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-03-08T01:00-04:00[UTC]")); +assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-03-08T01:00-04:00[UTC]", { offset: "reject" })); diff --git a/test/staging/Temporal/ZonedDateTime/old/string-parsing.js b/test/staging/Temporal/ZonedDateTime/old/string-parsing.js deleted file mode 100644 index e2c81478ed..0000000000 --- a/test/staging/Temporal/ZonedDateTime/old/string-parsing.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal-zoneddatetime-objects -description: string parsing -features: [Temporal] ----*/ - -// any number of decimal places -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1-08:00[-08:00]") }`, "1976-11-18T15:23:30.1-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12-08:00[-08:00]") }`, "1976-11-18T15:23:30.12-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123-08:00[-08:00]") }`, "1976-11-18T15:23:30.123-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1234-08:00[-08:00]") }`, "1976-11-18T15:23:30.1234-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12345-08:00[-08:00]") }`, "1976-11-18T15:23:30.12345-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456-08:00[-08:00]") }`, "1976-11-18T15:23:30.123456-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.1234567-08:00[-08:00]") }`, "1976-11-18T15:23:30.1234567-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.12345678-08:00[-08:00]") }`, "1976-11-18T15:23:30.12345678-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-08:00[-08:00]") }`, "1976-11-18T15:23:30.123456789-08:00[-08:00]"); - -// variant decimal separator -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30,12-08:00[-08:00]") }`, "1976-11-18T15:23:30.12-08:00[-08:00]"); - -// negative extended year -assert.sameValue(`${ Temporal.ZonedDateTime.from("-009999-11-18T15:23:30.12+00:00[UTC]") }`, "-009999-11-18T15:23:30.12+00:00[UTC]"); - -// mixture of basic and extended format -[ - "1976-11-18T152330.1-08:00[-08:00]", - "19761118T15:23:30.1-08:00[-08:00]", - "1976-11-18T15:23:30.1-0800[-08:00]", - "1976-11-18T152330.1-0800[-08:00]", - "19761118T15:23:30.1-0800[-08:00]", - "19761118T152330.1-08:00[-08:00]", - "19761118T152330.1-0800[-08:00]", - "+001976-11-18T152330.1-08:00[-08:00]", - "+0019761118T15:23:30.1-08:00[-08:00]", - "+001976-11-18T15:23:30.1-0800[-08:00]", - "+001976-11-18T152330.1-0800[-08:00]", - "+0019761118T15:23:30.1-0800[-08:00]", - "+0019761118T152330.1-08:00[-08:00]", - "+0019761118T152330.1-0800[-08:00]" -].forEach(input => assert.sameValue(`${ Temporal.ZonedDateTime.from(input) }`, "1976-11-18T15:23:30.1-08:00[-08:00]")); - -// optional parts -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15:23:30-08[-08:00]") }`, "1976-11-18T15:23:30-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("1976-11-18T15-08:00[-08:00]") }`, "1976-11-18T15:00:00-08:00[-08:00]"); -assert.sameValue(`${ Temporal.ZonedDateTime.from("2020-01-01[+09:00]") }`, "2020-01-01T00:00:00+09:00[+09:00]"); - -// no junk at end of string -assert.throws(RangeError, () => Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-08:00[-08:00]junk")) - -// constrain has no effect on invalid ISO string -assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-13-34T24:60[-08:00]", { overflow: "constrain" })); - -// { offset: 'reject' } throws if offset does not match IANA time zone -assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-03-08T01:00-04:00[UTC]")); -assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-03-08T01:00-04:00[UTC]", { offset: "reject" })); - -// throw when bad disambiguation -[ - "", - "EARLIER", - "balance" -].forEach(disambiguation => { - assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-11-01T04:00[-08:00]", { disambiguation })); -});