From 8e0c895c4ddca10a4e6f949ef3166c05754a755f 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 | 46 ++++++++++++++++ .../argument-string-with-time-designator.js | 29 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 46 ++++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 46 ++++++++++++++++ .../argument-string-with-time-designator.js | 29 ++++++++++ .../argument-string-no-implicit-midnight.js | 21 +++++++ ...-designator-required-for-disambiguation.js | 55 +++++++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ .../argument-string-no-implicit-midnight.js | 15 +++++ ...-designator-required-for-disambiguation.js | 44 +++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 46 ++++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 46 ++++++++++++++++ .../argument-string-with-time-designator.js | 29 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 46 ++++++++++++++++ .../argument-string-with-time-designator.js | 29 ++++++++++ .../argument-string-no-implicit-midnight.js | 16 ++++++ ...-designator-required-for-disambiguation.js | 46 ++++++++++++++++ .../argument-string-with-time-designator.js | 28 ++++++++++ 27 files changed, 825 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 0000000000..d19c1c873f --- /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 0000000000..243f3de920 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,46 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + `${string} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..dadb5671b9 --- /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 0000000000..a43275ed43 --- /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 0000000000..8c87428825 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,46 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), + `${string} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..ac7574838d --- /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 0000000000..bafdf31c01 --- /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 0000000000..2b0988cda5 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,46 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => instance.withPlainTime(arg), + `${string} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..6a7f7a4620 --- /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 0000000000..eec9db0085 --- /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 0000000000..1fc7ead2d0 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/compare/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,55 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => Temporal.PlainTime.compare(arg, midnight), + `${string} is ambiguous and requires T prefix (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainTime.compare(midnight, arg), + `${string} is ambiguous and requires T prefix (second argument)` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..de5ac08448 --- /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 0000000000..fcfdd640e9 --- /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 0000000000..15f5f10548 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/from/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,44 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => Temporal.PlainTime.from(arg), + `${string} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..8938b918ce --- /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 0000000000..63a8a48421 --- /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 0000000000..ca750d2eb7 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,46 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => instance.equals(arg), + `${string} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..2b6cded824 --- /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 0000000000..354223c0f5 --- /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 0000000000..5318a2177b --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,46 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => instance.since(arg), + `${string} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..f3121e62ee --- /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 0000000000..fa91414361 --- /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 0000000000..785e1efe69 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,46 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => instance.until(arg), + `${string} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..3482289d5b --- /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 0000000000..c828765187 --- /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 0000000000..129743e863 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-time-designator-required-for-disambiguation.js @@ -0,0 +1,46 @@ +// 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((string) => { + let arg = string; + assert.throws( + RangeError, + () => instance.withPlainTime(arg), + `${string} is ambiguous and requires T prefix` + ); + // The same string with a T prefix should not throw: + arg = `T${string}`; + 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 0000000000..49b151907b --- /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}`); +});