From effbdb4d0117ec371d827cda5893847c5e778819 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 17 Jan 2022 16:48:10 -0800 Subject: [PATCH] Test 'T' time designator prefix in PlainTime strings https://github.com/tc39/proposal-temporal/pull/1952 added support for time designator prefixes in PlainTime strings. This adds three tests to all entry points that convert an ISO string to a PlainTime: - no-implicit-midnight: ISO strings with only a date and no time are no longer accepted. Previously they were implicitly interpreted as 00:00. - with-time-designator: Tests that various forms of string with time designator are correctly parsed. - time-designator-required-for-disambiguation: Tests various cases where a string without a time designator is ambiguous and therefore the time designator is required, as well as various cases that implementations might assume are ambiguous but in fact are not. This was a normative change that achieved consensus at the December 2021 TC39 meeting. --- .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 45 ++++++++++++++++ .../argument-string-with-time-designator.js | 29 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 45 ++++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 45 ++++++++++++++++ .../argument-string-with-time-designator.js | 29 ++++++++++ .../argument-string-no-implicit-midnight.js | 21 ++++++++ ...-designator-required-for-disambiguation.js | 54 +++++++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ .../argument-string-no-implicit-midnight.js | 15 ++++++ ...-designator-required-for-disambiguation.js | 43 +++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 45 ++++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 45 ++++++++++++++++ .../argument-string-with-time-designator.js | 29 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 45 ++++++++++++++++ .../argument-string-with-time-designator.js | 29 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 45 ++++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ 27 files changed, 816 insertions(+) create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-with-time-designator.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-with-time-designator.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-with-time-designator.js create mode 100644 test/built-ins/Temporal/PlainTime/compare/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/PlainTime/compare/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/PlainTime/compare/argument-string-with-time-designator.js create mode 100644 test/built-ins/Temporal/PlainTime/from/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/PlainTime/from/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/PlainTime/from/argument-string-with-time-designator.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-with-time-designator.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/since/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/since/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/since/argument-string-with-time-designator.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/until/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/until/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/until/argument-string-with-time-designator.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-with-time-designator.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..d19c1c873f6 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-no-implicit-midnight.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.plaindate.prototype.toplaindatetime +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +const instance = new Temporal.PlainDate(2000, 5, 2); +assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + "Date-only string throws, does not implicitly convert to midnight" +); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..100abe14781 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,45 @@ +// 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.plaindate.prototype.toplaindatetime +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + `${arg} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + instance.toPlainDateTime(arg); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => instance.toPlainDateTime(arg)); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-with-time-designator.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-with-time-designator.js new file mode 100644 index 00000000000..dadb5671b98 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-with-time-designator.js @@ -0,0 +1,29 @@ +// 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.plaindate.prototype.toplaindatetime +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +includes: [temporalHelpers.js] +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainDate(2000, 1, 1); +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + const result = instance.toPlainDateTime(arg); + TemporalHelpers.assertPlainDateTime(result, 2000, 1, "M01", 1, 0, 30, 0, 0, 0, 0, `T prefix is accepted: ${arg}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..a43275ed432 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-no-implicit-midnight.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.plaindate.prototype.tozoneddatetime +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +const instance = new Temporal.PlainDate(2000, 5, 2); +assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), + "Date-only string throws, does not implicitly convert to midnight" +); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..cbdc6ff1280 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,45 @@ +// 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.plaindate.prototype.tozoneddatetime +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), + `${arg} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" })); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-with-time-designator.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-with-time-designator.js new file mode 100644 index 00000000000..ac7574838d1 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-with-time-designator.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.plaindate.prototype.tozoneddatetime +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainDate(2000, 1, 1); +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + const result = instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }); + assert.sameValue(result.epochNanoseconds, 946686600_000_000_000n, `T prefix is accepted: ${arg}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..bafdf31c01e --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight.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.plaindatetime.prototype.withplaintime +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); +assert.throws( + RangeError, + () => instance.withPlainTime(arg), + "Date-only string throws, does not implicitly convert to midnight" +); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..d8d60c9faa3 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,45 @@ +// 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.plaindatetime.prototype.withplaintime +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => instance.withPlainTime(arg), + `${arg} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + instance.withPlainTime(arg); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => instance.withPlainTime(arg)); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-with-time-designator.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-with-time-designator.js new file mode 100644 index 00000000000..6a7f7a4620c --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-with-time-designator.js @@ -0,0 +1,29 @@ +// 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.plaindatetime.prototype.withplaintime +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +includes: [temporalHelpers.js] +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 1, 1, 12, 30, 45, 123, 456, 789); +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + const result = instance.withPlainTime(arg); + TemporalHelpers.assertPlainDateTime(result, 2000, 1, "M01", 1, 0, 30, 0, 0, 0, 0, `T prefix is accepted: ${arg}`); +}); diff --git a/test/built-ins/Temporal/PlainTime/compare/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/PlainTime/compare/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..eec9db0085e --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/compare/argument-string-no-implicit-midnight.js @@ -0,0 +1,21 @@ +// 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.plaintime.compare +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +const midnight = new Temporal.PlainTime(); +assert.throws( + RangeError, + () => Temporal.PlainTime.compare(arg, midnight), + "Date-only string throws, does not implicitly convert to midnight (first argument)" +); +assert.throws( + RangeError, + () => Temporal.PlainTime.compare(midnight, arg), + "Date-only string throws, does not implicitly convert to midnight (second argument)" +); diff --git a/test/built-ins/Temporal/PlainTime/compare/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/PlainTime/compare/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..ace4db83042 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/compare/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,54 @@ +// 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.plaintime.compare +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const midnight = new Temporal.PlainTime(); + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => Temporal.PlainTime.compare(arg, midnight), + `${arg} is ambiguous and requires T prefix (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainTime.compare(midnight, arg), + `${arg} is ambiguous and requires T prefix (second argument)` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + Temporal.PlainTime.compare(arg, midnight); + Temporal.PlainTime.compare(midnight, arg); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => { + Temporal.PlainTime.compare(arg, midnight); + Temporal.PlainTime.compare(midnight, arg); +}); diff --git a/test/built-ins/Temporal/PlainTime/compare/argument-string-with-time-designator.js b/test/built-ins/Temporal/PlainTime/compare/argument-string-with-time-designator.js new file mode 100644 index 00000000000..de5ac084489 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/compare/argument-string-with-time-designator.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.plaintime.compare +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +features: [Temporal, arrow-function] +---*/ + +const halfPast = new Temporal.PlainTime(0, 30); +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + assert.sameValue(Temporal.PlainTime.compare(arg, halfPast), 0, `T prefix is accepted: ${arg} (first argument)`); + assert.sameValue(Temporal.PlainTime.compare(halfPast, arg), 0, `T prefix is accepted: ${arg} (second argument)`); +}); diff --git a/test/built-ins/Temporal/PlainTime/from/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/PlainTime/from/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..fcfdd640e90 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/from/argument-string-no-implicit-midnight.js @@ -0,0 +1,15 @@ +// 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.plaintime.from +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +assert.throws( + RangeError, + () => Temporal.PlainTime.from(arg), + "Date-only string throws, does not implicitly convert to midnight" +); diff --git a/test/built-ins/Temporal/PlainTime/from/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/PlainTime/from/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..a6714d4a165 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/from/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,43 @@ +// 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.plaintime.from +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => Temporal.PlainTime.from(arg), + `${arg} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + Temporal.PlainTime.from(arg); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => Temporal.PlainTime.from(arg)); diff --git a/test/built-ins/Temporal/PlainTime/from/argument-string-with-time-designator.js b/test/built-ins/Temporal/PlainTime/from/argument-string-with-time-designator.js new file mode 100644 index 00000000000..8938b918ce0 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/from/argument-string-with-time-designator.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.plaintime.from +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +includes: [temporalHelpers.js] +features: [Temporal, arrow-function] +---*/ + +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + const result = Temporal.PlainTime.from(arg); + TemporalHelpers.assertPlainTime(result, 0, 30, 0, 0, 0, 0, `T prefix is accepted: ${arg}`); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..63a8a484213 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-no-implicit-midnight.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.plaintime.prototype.equals +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); +assert.throws( + RangeError, + () => instance.equals(arg), + "Date-only string throws, does not implicitly convert to midnight" +); diff --git a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..21def8c4261 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,45 @@ +// 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.plaintime.prototype.equals +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => instance.equals(arg), + `${arg} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + instance.equals(arg); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => instance.equals(arg)); diff --git a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-with-time-designator.js b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-with-time-designator.js new file mode 100644 index 00000000000..2b6cded8244 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-with-time-designator.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.plaintime.prototype.equals +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainTime(0, 30, 0, 0, 0, 0); +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + const result = instance.equals(arg); + assert.sameValue(result, true, `T prefix is accepted: ${arg}`); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..354223c0f52 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-no-implicit-midnight.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.plaintime.prototype.since +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); +assert.throws( + RangeError, + () => instance.since(arg), + "Date-only string throws, does not implicitly convert to midnight" +); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..c7036b65407 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,45 @@ +// 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.plaintime.prototype.since +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => instance.since(arg), + `${arg} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + instance.since(arg); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => instance.since(arg)); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-with-time-designator.js b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-with-time-designator.js new file mode 100644 index 00000000000..f3121e62eec --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-with-time-designator.js @@ -0,0 +1,29 @@ +// 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.plaintime.prototype.since +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +includes: [temporalHelpers.js] +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainTime(1, 0, 0, 0, 0, 1); +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + const result = instance.since(arg); + TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 30, 0, 0, 0, 1, `T prefix is accepted: ${arg}`); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..fa914143618 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-no-implicit-midnight.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.plaintime.prototype.until +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); +assert.throws( + RangeError, + () => instance.until(arg), + "Date-only string throws, does not implicitly convert to midnight" +); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..c4b50393c9d --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,45 @@ +// 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.plaintime.prototype.until +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => instance.until(arg), + `${arg} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + instance.until(arg); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => instance.until(arg)); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-with-time-designator.js b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-with-time-designator.js new file mode 100644 index 00000000000..3482289d5b2 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-with-time-designator.js @@ -0,0 +1,29 @@ +// 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.plaintime.prototype.until +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +includes: [temporalHelpers.js] +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.PlainTime(1, 0, 0, 0, 0, 1); +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + const result = instance.until(arg); + TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, -30, 0, 0, 0, -1, `T prefix is accepted: ${arg}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight.js new file mode 100644 index 00000000000..c8287651871 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-no-implicit-midnight.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.prototype.withplaintime +description: RangeError thrown if a date-only string is passed in a PlainTime context +features: [Temporal, arrow-function] +---*/ + +const arg = "2019-10-01"; +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); +assert.throws( + RangeError, + () => instance.withPlainTime(arg), + "Date-only string throws, does not implicitly convert to midnight" +); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js new file mode 100644 index 00000000000..b48abb6aa51 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,45 @@ +// 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.prototype.withplaintime +description: ISO 8601 time designator "T" required in cases of ambiguity +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +const ambiguousStrings = [ + "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "1214", // ambiguity between MMDD and HHMM + "0229", // ditto, including MMDD that doesn't occur every year + "1130", // ditto, including DD that doesn't occur in every month + "12-14", // ambiguity between MM-DD and HH-UU + "202112", // ambiguity between YYYYMM and HHMMSS +]; +ambiguousStrings.forEach((arg) => { + assert.throws( + RangeError, + () => instance.withPlainTime(arg), + `${arg} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${arg}`; + instance.withPlainTime(arg); +}); + +// None of these should throw without a T prefix, because they are unambiguously time strings: +const unambiguousStrings = [ + "2021-13", // 13 is not a month + "202113", // ditto + "0000-00", // 0 is not a month + "000000", // ditto + "1314", // 13 is not a month + "13-14", // ditto + "1232", // 32 is not a day + "0230", // 30 is not a day in February + "0631", // 31 is not a day in June + "0000", // 0 is neither a month nor a day + "00-00", // ditto +]; +unambiguousStrings.forEach((arg) => instance.withPlainTime(arg)); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-with-time-designator.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-with-time-designator.js new file mode 100644 index 00000000000..49b151907b0 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-with-time-designator.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.prototype.withplaintime +description: ISO 8601 time designator "T" allowed at the start of PlainTime strings +features: [Temporal, arrow-function] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); +const validStrings = [ + "T00:30", + "t00:30", + "T0030", + "t0030", + "T00:30:00", + "t00:30:00", + "T003000", + "t003000", + "T00:30:00.000000000", + "t00:30:00.000000000", + "T003000.000000000", + "t003000.000000000", +]; +validStrings.forEach((arg) => { + const result = instance.withPlainTime(arg); + assert.sameValue(result.epochNanoseconds, 999995400_000_000_000n, `T prefix is accepted: ${arg}`); +});