diff --git a/harness/temporalHelpers.js b/harness/temporalHelpers.js index b5f47d8f6fa..8ad27bb2b39 100644 --- a/harness/temporalHelpers.js +++ b/harness/temporalHelpers.js @@ -1845,11 +1845,14 @@ var TemporalHelpers = { plainTimeStringsAmbiguous() { const ambiguousStrings = [ "2021-12", // ambiguity between YYYY-MM and HHMM-UU + "2021-12[-12:00]", // ditto, TZ does not disambiguate "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 + "12-14[-14:00]", // ditto, TZ does not disambiguate "202112", // ambiguity between YYYYMM and HHMMSS + "202112[UTC]", // ditto, TZ does not disambiguate ]; // Adding a calendar annotation to one of these strings must not cause // disambiguation in favour of time. @@ -1879,8 +1882,6 @@ var TemporalHelpers = { "0631", // 31 is not a day in June "0000", // 0 is neither a month nor a day "00-00", // ditto - "2021-12[-12:00]", // HHMM-UU is ambiguous with YYYY-MM, but TZ disambiguates - "202112[UTC]", // HHMMSS is ambiguous with YYYYMM, but TZ disambiguates ]; }, diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..d1783d50ca7 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-date-with-utc-offset.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.calendar.prototype.dateadd +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.dateAdd(arg, new Temporal.Duration()); + + TemporalHelpers.assertPlainDate( + result, + 2000, 5, "M05", 2, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.dateAdd(arg, new Temporal.Duration()), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-time-zone-annotation.js index c4f942d1470..32e92eb78d5 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-time-zone-annotation.js @@ -9,14 +9,10 @@ includes: [temporalHelpers.js] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..1d923f43b37 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-date-with-utc-offset.js @@ -0,0 +1,49 @@ +// 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.calendar.prototype.dateuntil +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + TemporalHelpers.assertDuration( + instance.dateUntil(arg, arg), + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), + `"${arg}" UTC offset without time is not valid for PlainDate (first argument)` + ); + assert.throws( + RangeError, + () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), + `"${arg}" UTC offset without time is not valid for PlainDate (second argument)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-time-zone-annotation.js index d64c8c5164b..77511ae0078 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-time-zone-annotation.js @@ -9,14 +9,10 @@ includes: [temporalHelpers.js] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ['2000-05-02[Asia/Kolkata]', 'named, with no time'], + ['2000-05-02[!Europe/Vienna]', 'named, with ! and no time'], + ['2000-05-02[+00:00]', 'numeric, with no time'], + ['2000-05-02[!-02:30]', 'numeric, with ! and no time'], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/day/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/day/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..76bbfee6a50 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day/argument-string-date-with-utc-offset.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.calendar.prototype.day +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.day(arg); + + assert.sameValue( + result, + 2, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.day(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/day/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/day/argument-string-time-zone-annotation.js index 82bb780b27b..8145e8c70f9 100644 --- a/test/built-ins/Temporal/Calendar/prototype/day/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/day/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..b078c711f48 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-date-with-utc-offset.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.calendar.prototype.dayofweek +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.dayOfWeek(arg); + + assert.sameValue( + result, + 2, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.dayOfWeek(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-time-zone-annotation.js index e7e14714631..36182fdd4b1 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..6aec6f3c0fb --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-date-with-utc-offset.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.calendar.prototype.dayofyear +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.dayOfYear(arg); + + assert.sameValue( + result, + 123, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.dayOfYear(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-time-zone-annotation.js index b176931cdf9..8978c0ccbde 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..2ef94ed68cb --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-date-with-utc-offset.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.calendar.prototype.daysinmonth +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.daysInMonth(arg); + + assert.sameValue( + result, + 31, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.daysInMonth(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-time-zone-annotation.js index 71fb85359f8..36d7a5d194a 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..ac216a5ffad --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-date-with-utc-offset.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.calendar.prototype.daysinweek +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.daysInWeek(arg); + + assert.sameValue( + result, + 7, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.daysInWeek(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-time-zone-annotation.js index 8c39859f32a..82603259fea 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..dcebadfb47d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-string-date-with-utc-offset.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.calendar.prototype.daysinyear +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.daysInYear(arg); + + assert.sameValue( + result, + 366, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.daysInYear(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-string-time-zone-annotation.js index 064d1fe3e6e..1821d2d7cd5 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..e13911f52b0 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string-date-with-utc-offset.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.calendar.prototype.inleapyear +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.inLeapYear(arg); + + assert.sameValue( + result, + true, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.inLeapYear(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string-time-zone-annotation.js index 3a2844bc081..98e496c32f2 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/month/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/month/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..8084e0e1588 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/month/argument-string-date-with-utc-offset.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.calendar.prototype.month +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.month(arg); + + assert.sameValue( + result, + 5, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.month(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/month/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/month/argument-string-time-zone-annotation.js index dc31a960c5b..fa4bc3bd80b 100644 --- a/test/built-ins/Temporal/Calendar/prototype/month/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/month/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..ac8b7d67c57 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-string-date-with-utc-offset.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.calendar.prototype.monthcode +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.monthCode(arg); + + assert.sameValue( + result, + "M05", + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.monthCode(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-string-time-zone-annotation.js index 2ad914e3ee6..79b41879362 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..95018bc29d9 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-string-date-with-utc-offset.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.calendar.prototype.monthsinyear +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.monthsInYear(arg); + + assert.sameValue( + result, + 12, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.monthsInYear(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-string-time-zone-annotation.js index 0e13e59894a..baa576f82cf 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..e96547c23f8 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-date-with-utc-offset.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.calendar.prototype.weekofyear +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.weekOfYear(arg); + + assert.sameValue( + result, + 18, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.weekOfYear(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-time-zone-annotation.js index 9870ce77f8b..1149499fc1f 100644 --- a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Calendar/prototype/year/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Calendar/prototype/year/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..981f5939f00 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/year/argument-string-date-with-utc-offset.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.calendar.prototype.year +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.year(arg); + + assert.sameValue( + result, + 2000, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.year(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/year/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/Calendar/prototype/year/argument-string-time-zone-annotation.js index c6eec6f3f12..574421e7d4f 100644 --- a/test/built-ins/Temporal/Calendar/prototype/year/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/Calendar/prototype/year/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/Instant/compare/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Instant/compare/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..7d490f8712b --- /dev/null +++ b/test/built-ins/Temporal/Instant/compare/argument-string-date-with-utc-offset.js @@ -0,0 +1,53 @@ +// 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.instant.compare +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = Temporal.Instant.compare(arg, arg); + + assert.sameValue( + result, + 0, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; +const epoch = new Temporal.Instant(0n); + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.Instant.compare(arg, epoch), + `"${arg}" UTC offset without time is not valid for Instant (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.Instant.compare(epoch, arg), + `"${arg}" UTC offset without time is not valid for Instant (second argument)` + ); +} diff --git a/test/built-ins/Temporal/Instant/from/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Instant/from/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..23064bb12ea --- /dev/null +++ b/test/built-ins/Temporal/Instant/from/argument-string-date-with-utc-offset.js @@ -0,0 +1,47 @@ +// 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.instant.from +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = Temporal.Instant.from(arg); + + assert.sameValue( + result.epochNanoseconds, + 0n, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.Instant.from(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/Instant/prototype/equals/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Instant/prototype/equals/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..5224f6baae4 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/equals/argument-string-date-with-utc-offset.js @@ -0,0 +1,49 @@ +// 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.instant.prototype.equals +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(0n); + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = instance.equals(arg); + + assert.sameValue( + result, + true, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/Instant/prototype/since/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Instant/prototype/since/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..4b12adb75e5 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/argument-string-date-with-utc-offset.js @@ -0,0 +1,50 @@ +// 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.instant.prototype.since +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.Instant(0n); + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = instance.since(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/Instant/prototype/until/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/Instant/prototype/until/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..2b52ffb2513 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/argument-string-date-with-utc-offset.js @@ -0,0 +1,50 @@ +// 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.instant.prototype.until +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.Instant(0n); + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = instance.until(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDate/compare/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..9b3ae0c2efc --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/compare/argument-string-date-with-utc-offset.js @@ -0,0 +1,48 @@ +// 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.compare +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainDate.compare(arg, arg); + + assert.sameValue( + result, + 0, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), + `"${arg}" UTC offset without time is not valid for PlainDate (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), + `"${arg}" UTC offset without time is not valid for PlainDate (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/PlainDate/compare/argument-string-time-zone-annotation.js index 68655e917c8..964fe9a8a57 100644 --- a/test/built-ins/Temporal/PlainDate/compare/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/PlainDate/compare/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ['2000-05-02[Asia/Kolkata]', 'named, with no time'], + ['2000-05-02[!Europe/Vienna]', 'named, with ! and no time'], + ['2000-05-02[+00:00]', 'numeric, with no time'], + ['2000-05-02[!-02:30]', 'numeric, with ! and no time'], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/PlainDate/from/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDate/from/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..faf313c4adc --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/from/argument-string-date-with-utc-offset.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.plaindate.from +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainDate.from(arg); + + TemporalHelpers.assertPlainDate( + result, + 2000, 5, "M05", 2, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainDate.from(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/from/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/PlainDate/from/argument-string-time-zone-annotation.js index d07fc87fbb2..6fa41009342 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-string-time-zone-annotation.js @@ -9,14 +9,10 @@ includes: [temporalHelpers.js] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..cfe525a53e3 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-date-with-utc-offset.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.equals +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.equals(arg); + + assert.sameValue( + result, + true, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-time-zone-annotation.js index 0c92c35344f..19020c5b57a 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..0a6c8ae4383 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-date-with-utc-offset.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.since +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.since(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-time-zone-annotation.js index 6cf4dc58d01..ac599bead51 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-string-time-zone-annotation.js @@ -9,14 +9,10 @@ includes: [temporalHelpers.js] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..38f858db310 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-string-date-with-utc-offset.js @@ -0,0 +1,50 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.toPlainDateTime(arg); + + TemporalHelpers.assertPlainDateTime( + result, + 2000, 5, "M05", 2, 12, 34, 56, 987, 654, 321, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + `"${arg}" UTC offset without time is not valid for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..d303c88042e --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-string-date-with-utc-offset.js @@ -0,0 +1,49 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }); + + assert.sameValue( + result.epochNanoseconds, + 957_270_896_987_654_321n, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), + `"${arg}" UTC offset without time is not valid for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..c0f1505a79c --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-date-with-utc-offset.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.until +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.until(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-time-zone-annotation.js index f0ef737a5f6..39e54115169 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-string-time-zone-annotation.js @@ -9,14 +9,10 @@ includes: [temporalHelpers.js] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..703ee6e2316 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-string-date-with-utc-offset.js @@ -0,0 +1,48 @@ +// 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.compare +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const validStrings = [ + "1976-11-18T15:23+00:00", + "1976-11-18T15:23+00:00[UTC]", + "1976-11-18T15:23+00:00[!UTC]", + "1976-11-18T15:23-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainDateTime.compare(arg, arg); + + assert.sameValue( + result, + 0, + `"${arg}" is a valid UTC offset with time for PlainDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), + `"${arg}" UTC offset without time is not valid for PlainDateTime (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), + `"${arg}" UTC offset without time is not valid for PlainDateTime (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDateTime/from/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..29894e7ed3a --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-string-date-with-utc-offset.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.plaindatetime.from +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const validStrings = [ + "1976-11-18T15:23+00:00", + "1976-11-18T15:23+00:00[UTC]", + "1976-11-18T15:23+00:00[!UTC]", + "1976-11-18T15:23-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainDateTime.from(arg); + + TemporalHelpers.assertPlainDateTime( + result, + 1976, 11, "M11", 18, 15, 23, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainDateTime.from(arg), + `"${arg}" UTC offset without time is not valid for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..99bacb3620f --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-string-date-with-utc-offset.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.equals +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +const validStrings = [ + "1976-11-18T15:23+00:00", + "1976-11-18T15:23+00:00[UTC]", + "1976-11-18T15:23+00:00[!UTC]", + "1976-11-18T15:23-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.equals(arg); + + assert.sameValue( + result, + true, + `"${arg}" is a valid UTC offset with time for PlainDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" UTC offset without time is not valid for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..aeaa0f59d5c --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-string-date-with-utc-offset.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.since +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +const validStrings = [ + "1976-11-18T15:23+00:00", + "1976-11-18T15:23+00:00[UTC]", + "1976-11-18T15:23+00:00[!UTC]", + "1976-11-18T15:23-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.since(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" UTC offset without time is not valid for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..8ff74c4bbc7 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-string-date-with-utc-offset.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.until +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +const validStrings = [ + "1976-11-18T15:23+00:00", + "1976-11-18T15:23+00:00[UTC]", + "1976-11-18T15:23+00:00[!UTC]", + "1976-11-18T15:23-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.until(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" UTC offset without time is not valid for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..86c3b0d0d08 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-date-with-utc-offset.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.withplaindate +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.withPlainDate(arg); + + TemporalHelpers.assertPlainDateTime( + result, + 2000, 5, "M05", 2, 15, 23, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.withPlainDate(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-time-zone-annotation.js index 946197e5c99..c6440ef9cb1 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-string-time-zone-annotation.js @@ -9,14 +9,10 @@ includes: [temporalHelpers.js] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..04290430468 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-string-date-with-utc-offset.js @@ -0,0 +1,50 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23); + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.withPlainTime(arg); + + TemporalHelpers.assertPlainDateTime( + result, + 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.withPlainTime(arg), + `"${arg}" UTC offset without time is not valid for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..a645cc437e6 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-string-date-with-utc-offset.js @@ -0,0 +1,60 @@ +// 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.plainmonthday.from +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const validStrings = [ + "05-02[Asia/Katmandu]", + "05-02[!Asia/Katmandu]", + "05-02[u-ca=iso8601]", + "05-02[Asia/Tokyo][u-ca=iso8601]", + "--05-02[Asia/Katmandu]", + "--05-02[!Asia/Katmandu]", + "--05-02[u-ca=iso8601]", + "--05-02[Asia/Tokyo][u-ca=iso8601]", + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainMonthDay.from(arg); + + TemporalHelpers.assertPlainMonthDay( + result, + "M05", 2, + `"${arg}" is a valid UTC offset with time for PlainMonthDay` + ); +} + +const invalidStrings = [ + "09-15Z", + "09-15Z[UTC]", + "09-15+01:00", + "09-15+01:00[Europe/Vienna]", + "--09-15Z", + "--09-15Z[UTC]", + "--09-15+01:00", + "--09-15+01:00[Europe/Vienna]", + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", + "09-15[u-ca=chinese]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from(arg), + `"${arg}" UTC offset without time is not valid for PlainMonthDay` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..1263bf7fecf --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-string-date-with-utc-offset.js @@ -0,0 +1,61 @@ +// 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.plainmonthday.prototype.equals +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.PlainMonthDay(5, 2); + +const validStrings = [ + "05-02[Asia/Katmandu]", + "05-02[!Asia/Katmandu]", + "05-02[u-ca=iso8601]", + "05-02[Asia/Tokyo][u-ca=iso8601]", + "--05-02[Asia/Katmandu]", + "--05-02[!Asia/Katmandu]", + "--05-02[u-ca=iso8601]", + "--05-02[Asia/Tokyo][u-ca=iso8601]", + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.equals(arg); + + assert.sameValue( + result, + true, + `"${arg}" is a valid UTC offset with time for PlainMonthDay` + ); +} + +const invalidStrings = [ + "09-15Z", + "09-15Z[UTC]", + "09-15+01:00", + "09-15+01:00[Europe/Vienna]", + "--09-15Z", + "--09-15Z[UTC]", + "--09-15+01:00", + "--09-15+01:00[Europe/Vienna]", + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", + "09-15[u-ca=chinese]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" UTC offset without time is not valid for PlainMonthDay` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/compare/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainTime/compare/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..94e492b1a41 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/compare/argument-string-date-with-utc-offset.js @@ -0,0 +1,52 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainTime.compare(arg, arg); + + assert.sameValue( + result, + 0, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)), + `"${arg}" UTC offset without time is not valid for PlainTime (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg), + `"${arg}" UTC offset without time is not valid for PlainTime (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/from/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainTime/from/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..6009304300c --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/from/argument-string-date-with-utc-offset.js @@ -0,0 +1,48 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainTime.from(arg); + + TemporalHelpers.assertPlainTime( + result, + 12, 34, 56, 987, 654, 321, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainTime.from(arg), + `"${arg}" UTC offset without time is not valid for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..026229df346 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-string-date-with-utc-offset.js @@ -0,0 +1,49 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.equals(arg); + + assert.sameValue( + result, + true, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" UTC offset without time is not valid for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..e2fddce7417 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/argument-string-date-with-utc-offset.js @@ -0,0 +1,50 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.since(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" UTC offset without time is not valid for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..6690958207d --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-string-date-with-utc-offset.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.toplaindatetime +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.toPlainDateTime(arg); + + TemporalHelpers.assertPlainDateTime( + result, + 2000, 5, "M05", 2, 12, 34, 56, 987, 654, 321, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-string-time-zone-annotation.js index 3afdf3b1f27..346595ccb13 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-string-time-zone-annotation.js @@ -9,14 +9,10 @@ includes: [temporalHelpers.js] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..24266beb1ca --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-string-date-with-utc-offset.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.tozoneddatetime +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }); + + assert.sameValue( + result.epochNanoseconds, + 957_270_896_987_654_321n, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-string-time-zone-annotation.js index 197bb338013..5473e64c1a9 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..a51ce0b678c --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/argument-string-date-with-utc-offset.js @@ -0,0 +1,50 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.until(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" UTC offset without time is not valid for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..3b9dd33f2e5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-string-date-with-utc-offset.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.plainyearmonth.compare +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const validStrings = [ + "2019-12[Africa/Abidjan]", + "2019-12[!Africa/Abidjan]", + "2019-12[u-ca=iso8601]", + "2019-12[Africa/Abidjan][u-ca=iso8601]", + "2019-12-15T00+00:00", + "2019-12-15T00+00:00[UTC]", + "2019-12-15T00+00:00[!UTC]", + "2019-12-15T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainYearMonth.compare(arg, arg); + + assert.sameValue( + result, + 0, + `"${arg}" is a valid UTC offset with time for PlainYearMonth` + ); +} + +const invalidStrings = [ + "2022-09[u-ca=hebrew]", + "2022-09Z", + "2022-09+01:00", + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), + `"${arg}" UTC offset without time is not valid for PlainYearMonth (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), + `"${arg}" UTC offset without time is not valid for PlainYearMonth (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..c8f78dc833f --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-string-date-with-utc-offset.js @@ -0,0 +1,51 @@ +// 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.plainyearmonth.from +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const validStrings = [ + "2019-12[Africa/Abidjan]", + "2019-12[!Africa/Abidjan]", + "2019-12[u-ca=iso8601]", + "2019-12[Africa/Abidjan][u-ca=iso8601]", + "2019-12-15T00+00:00", + "2019-12-15T00+00:00[UTC]", + "2019-12-15T00+00:00[!UTC]", + "2019-12-15T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = Temporal.PlainYearMonth.from(arg); + + TemporalHelpers.assertPlainYearMonth( + result, + 2019, 12, "M12", + `"${arg}" is a valid UTC offset with time for PlainYearMonth` + ); +} + +const invalidStrings = [ + "2022-09[u-ca=hebrew]", + "2022-09Z", + "2022-09+01:00", + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from(arg), + `"${arg}" UTC offset without time is not valid for PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..8931d02cd14 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-string-date-with-utc-offset.js @@ -0,0 +1,52 @@ +// 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.plainyearmonth.prototype.equals +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 12); + +const validStrings = [ + "2019-12[Africa/Abidjan]", + "2019-12[!Africa/Abidjan]", + "2019-12[u-ca=iso8601]", + "2019-12[Africa/Abidjan][u-ca=iso8601]", + "2019-12-15T00+00:00", + "2019-12-15T00+00:00[UTC]", + "2019-12-15T00+00:00[!UTC]", + "2019-12-15T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.equals(arg); + + assert.sameValue( + result, + true, + `"${arg}" is a valid UTC offset with time for PlainYearMonth` + ); +} + +const invalidStrings = [ + "2022-09[u-ca=hebrew]", + "2022-09Z", + "2022-09+01:00", + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" UTC offset without time is not valid for PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..f5e92a00cb4 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-string-date-with-utc-offset.js @@ -0,0 +1,53 @@ +// 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.plainyearmonth.prototype.since +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 12); + +const validStrings = [ + "2019-12[Africa/Abidjan]", + "2019-12[!Africa/Abidjan]", + "2019-12[u-ca=iso8601]", + "2019-12[Africa/Abidjan][u-ca=iso8601]", + "2019-12-15T00+00:00", + "2019-12-15T00+00:00[UTC]", + "2019-12-15T00+00:00[!UTC]", + "2019-12-15T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.since(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainYearMonth` + ); +} + +const invalidStrings = [ + "2022-09[u-ca=hebrew]", + "2022-09Z", + "2022-09+01:00", + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" UTC offset without time is not valid for PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..7cb86114e71 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-string-date-with-utc-offset.js @@ -0,0 +1,53 @@ +// 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.plainyearmonth.prototype.until +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 12); + +const validStrings = [ + "2019-12[Africa/Abidjan]", + "2019-12[!Africa/Abidjan]", + "2019-12[u-ca=iso8601]", + "2019-12[Africa/Abidjan][u-ca=iso8601]", + "2019-12-15T00+00:00", + "2019-12-15T00+00:00[UTC]", + "2019-12-15T00+00:00[!UTC]", + "2019-12-15T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.until(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for PlainYearMonth` + ); +} + +const invalidStrings = [ + "2022-09[u-ca=hebrew]", + "2022-09Z", + "2022-09+01:00", + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" UTC offset without time is not valid for PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..873c89fc1b3 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-string-date-with-utc-offset.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.timezone.prototype.getinstantfor +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const validStrings = [ + "1976-11-18T15:23+00:00", + "1976-11-18T15:23+00:00[UTC]", + "1976-11-18T15:23+00:00[!UTC]", + "1976-11-18T15:23-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.getInstantFor(arg); + + assert.sameValue( + result.epochNanoseconds, + 217_178_580_000_000_000n, + `"${arg}" is a valid UTC offset with time for PlainDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.getInstantFor(arg), + `"${arg}" UTC offset without time is not valid for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..bc4474c4f27 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-string-date-with-utc-offset.js @@ -0,0 +1,49 @@ +// 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.timezone.prototype.getnexttransition +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = instance.getNextTransition(arg); + + assert.sameValue( + result, + null, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.getNextTransition(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..82bde800c9b --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-string-date-with-utc-offset.js @@ -0,0 +1,49 @@ +// 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.timezone.prototype.getoffsetnanosecondsfor +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = instance.getOffsetNanosecondsFor(arg); + + assert.sameValue( + result, + 0, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.getOffsetNanosecondsFor(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..92263384b10 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-string-date-with-utc-offset.js @@ -0,0 +1,49 @@ +// 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.timezone.prototype.getoffsetstringfor +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = instance.getOffsetStringFor(arg); + + assert.sameValue( + result, + "+00:00", + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.getOffsetStringFor(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..23c2f1a5b3f --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-string-date-with-utc-offset.js @@ -0,0 +1,50 @@ +// 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.timezone.prototype.getplaindatetimefor +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = instance.getPlainDateTimeFor(arg); + + TemporalHelpers.assertPlainDateTime( + result, + 1970, 1, "M01", 1, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.getPlainDateTimeFor(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..11239a95502 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-string-date-with-utc-offset.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.timezone.prototype.getpossibleinstantsfor +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [compareArray.js] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const validStrings = [ + "1976-11-18T15:23+00:00", + "1976-11-18T15:23+00:00[UTC]", + "1976-11-18T15:23+00:00[!UTC]", + "1976-11-18T15:23-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.getPossibleInstantsFor(arg); + + assert.compareArray( + result.map(i => i.epochNanoseconds), + [217_178_580_000_000_000n], + `"${arg}" is a valid UTC offset with time for PlainDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.getPossibleInstantsFor(arg), + `"${arg}" UTC offset without time is not valid for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..32aab26472e --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-string-date-with-utc-offset.js @@ -0,0 +1,49 @@ +// 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.timezone.prototype.getprevioustransition +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const validStrings = [ + "1970-01-01T00Z", + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00Z[Europe/Vienna]", + "1970-01-01T00+00:00", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", + "1969-12-31T16-08:00[America/Vancouver]", +]; + +for (const arg of validStrings) { + const result = instance.getPreviousTransition(arg); + + assert.sameValue( + result, + null, + `"${arg}" is a valid UTC offset with time for Instant` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.getPreviousTransition(arg), + `"${arg}" UTC offset without time is not valid for Instant` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..a162f455cf5 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-string-date-with-utc-offset.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.compare +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const validStrings = [ + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", +]; + +for (const arg of validStrings) { + const result = Temporal.ZonedDateTime.compare(arg, arg); + + assert.sameValue( + result, + 0, + `"${arg}" is a valid UTC offset with time for ZonedDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30[America/St_Johns]", +]; +const datetime = new Temporal.ZonedDateTime(0n, "UTC"); + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(arg, datetime), + `"${arg}" UTC offset without time is not valid for ZonedDateTime (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(datetime, arg), + `"${arg}" UTC offset without time is not valid for ZonedDateTime (second argument)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..eab1c442029 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-string-date-with-utc-offset.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const validStrings = [ + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", +]; + +for (const arg of validStrings) { + const result = Temporal.ZonedDateTime.from(arg); + + assert.sameValue( + result.timeZone.toString(), + "UTC", + `"${arg}" is a valid UTC offset with time for ZonedDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.from(arg), + `"${arg}" UTC offset without time is not valid for ZonedDateTime` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..6892a971050 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-string-date-with-utc-offset.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.zoneddatetime.prototype.equals +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const validStrings = [ + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", +]; + +for (const arg of validStrings) { + const result = instance.equals(arg); + + assert.sameValue( + result, + true, + `"${arg}" is a valid UTC offset with time for ZonedDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.equals(arg), + `"${arg}" UTC offset without time is not valid for ZonedDateTime` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..6ceb051eb3a --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-string-date-with-utc-offset.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.zoneddatetime.prototype.since +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const validStrings = [ + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", +]; + +for (const arg of validStrings) { + const result = instance.since(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for ZonedDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.since(arg), + `"${arg}" UTC offset without time is not valid for ZonedDateTime` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..5e36bdaf703 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-string-date-with-utc-offset.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.zoneddatetime.prototype.until +description: UTC offset not valid with format that does not include a time +features: [Temporal] +includes: [temporalHelpers.js] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const validStrings = [ + "1970-01-01T00Z[UTC]", + "1970-01-01T00Z[!UTC]", + "1970-01-01T00+00:00[UTC]", + "1970-01-01T00+00:00[!UTC]", +]; + +for (const arg of validStrings) { + const result = instance.until(arg); + + TemporalHelpers.assertDuration( + result, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + `"${arg}" is a valid UTC offset with time for ZonedDateTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.until(arg), + `"${arg}" UTC offset without time is not valid for ZonedDateTime` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..a0b336bf4ac --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-string-date-with-utc-offset.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.withplaindate +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.withPlainDate(arg); + + assert.sameValue( + result.epochNanoseconds, + 957_225_600_000_000_000n, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.withPlainDate(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-string-time-zone-annotation.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-string-time-zone-annotation.js index a4e81898965..2fd7df81f7f 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-string-time-zone-annotation.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-date-with-utc-offset.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..d50b266807b --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-string-date-with-utc-offset.js @@ -0,0 +1,50 @@ +// 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: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const validStrings = [ + "12:34:56.987654321+00:00", + "12:34:56.987654321+00:00[UTC]", + "12:34:56.987654321+00:00[!UTC]", + "12:34:56.987654321-02:30[America/St_Johns]", + "1976-11-18T12:34:56.987654321+00:00", + "1976-11-18T12:34:56.987654321+00:00[UTC]", + "1976-11-18T12:34:56.987654321+00:00[!UTC]", + "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.withPlainTime(arg); + + assert.sameValue( + result.epochNanoseconds, + 45_296_987_654_321n, + `"${arg}" is a valid UTC offset with time for PlainTime` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.withPlainTime(arg), + `"${arg}" UTC offset without time is not valid for PlainTime` + ); +} diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-string-date-with-utc-offset.js b/test/intl402/Temporal/Calendar/prototype/era/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..11313edf849 --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/era/argument-string-date-with-utc-offset.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.calendar.prototype.era +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.era(arg); + + assert.sameValue( + result, + undefined, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.era(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-string-time-zone-annotation.js b/test/intl402/Temporal/Calendar/prototype/era/argument-string-time-zone-annotation.js index 2a4ac233cbc..899b979f21a 100644 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-string-time-zone-annotation.js +++ b/test/intl402/Temporal/Calendar/prototype/era/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-date-with-utc-offset.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-date-with-utc-offset.js new file mode 100644 index 00000000000..fa453e180c8 --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-date-with-utc-offset.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.calendar.prototype.erayear +description: UTC offset not valid with format that does not include a time +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const validStrings = [ + "2000-05-02T00+00:00", + "2000-05-02T00+00:00[UTC]", + "2000-05-02T00+00:00[!UTC]", + "2000-05-02T00-02:30[America/St_Johns]", +]; + +for (const arg of validStrings) { + const result = instance.eraYear(arg); + + assert.sameValue( + result, + undefined, + `"${arg}" is a valid UTC offset with time for PlainDate` + ); +} + +const invalidStrings = [ + "2022-09-15Z", + "2022-09-15Z[UTC]", + "2022-09-15Z[Europe/Vienna]", + "2022-09-15+00:00", + "2022-09-15+00:00[UTC]", + "2022-09-15-02:30", + "2022-09-15-02:30[America/St_Johns]", +]; + +for (const arg of invalidStrings) { + assert.throws( + RangeError, + () => instance.eraYear(arg), + `"${arg}" UTC offset without time is not valid for PlainDate` + ); +} diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-time-zone-annotation.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-time-zone-annotation.js index efe71d875e5..14a71d5268d 100644 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-time-zone-annotation.js +++ b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-string-time-zone-annotation.js @@ -8,14 +8,10 @@ features: [Temporal] ---*/ const tests = [ - ["2000-05-02[Asia/Kolkata]", "named, with no time and no offset"], - ["2000-05-02[!Europe/Vienna]", "named, with !, no time, and no offset"], - ["2000-05-02[+00:00]", "numeric, with no time and no offset"], - ["2000-05-02[!-02:30]", "numeric, with !, no time, and no offset"], - ["2000-05-02+00:00[UTC]", "named, with offset and no time"], - ["2000-05-02+00:00[!Africa/Abidjan]", "named, with offset, !, and no time"], - ["2000-05-02+00:00[-08:00]", "numeric, with offset and no time"], - ["2000-05-02+00:00[!+01:00]", "numeric, with offset, !, and no time"], + ["2000-05-02[Asia/Kolkata]", "named, with no time"], + ["2000-05-02[!Europe/Vienna]", "named, with ! and no time"], + ["2000-05-02[+00:00]", "numeric, with no time"], + ["2000-05-02[!-02:30]", "numeric, with ! and no time"], ["2000-05-02T15:23[America/Sao_Paulo]", "named, with no offset"], ["2000-05-02T15:23[!Asia/Tokyo]", "named, with ! and no offset"], ["2000-05-02T15:23[-02:30]", "numeric, with no offset"], diff --git a/test/staging/Temporal/Regex/old/instant.js b/test/staging/Temporal/Regex/old/instant.js index 9602b0fbc45..218799e150a 100644 --- a/test/staging/Temporal/Regex/old/instant.js +++ b/test/staging/Temporal/Regex/old/instant.js @@ -28,14 +28,6 @@ function generateTest(dateTimeString, zoneString, components) { test(`${ dateTimeString }:30.123456789${ zoneString }`, components); } // valid strings -test("2020-01-01Z", [ - 2020, - 1, - 1, - 0, - 0, - 0 -]); [ "+01:00", "+01",