From bc0e006de4ac7ce922410cbf2c1e4488addacb58 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 28 Jul 2022 17:11:59 -0700 Subject: [PATCH] Temporal: Add tests for casting a time zone ID string to a Temporal.TimeZone This adds tests to every entry point where a Temporal.TimeZone is accepted, making sure that a time zone ID string is also accepted. --- .../Temporal/Duration/compare/timezone-string.js | 14 ++++++++++++++ .../Duration/prototype/add/timezone-string.js | 16 ++++++++++++++++ .../Duration/prototype/round/timezone-string.js | 16 ++++++++++++++++ .../prototype/subtract/timezone-string.js | 16 ++++++++++++++++ .../Duration/prototype/total/timezone-string.js | 16 ++++++++++++++++ .../prototype/toString/timezone-string.js | 16 ++++++++++++++++ .../prototype/toZonedDateTime/timezone-string.js | 15 +++++++++++++++ .../toZonedDateTimeISO/timezone-string.js | 15 +++++++++++++++ .../Temporal/Now/plainDate/timezone-string.js | 14 ++++++++++++++ .../Temporal/Now/plainDateISO/timezone-string.js | 14 ++++++++++++++ .../Now/plainDateTime/timezone-string.js | 14 ++++++++++++++ .../Now/plainDateTimeISO/timezone-string.js | 14 ++++++++++++++ .../Temporal/Now/plainTimeISO/timezone-string.js | 14 ++++++++++++++ .../Now/zonedDateTime/timezone-string.js | 13 +++++++++++++ .../Now/zonedDateTimeISO/timezone-string.js | 13 +++++++++++++ .../prototype/toZonedDateTime/timezone-string.js | 15 +++++++++++++++ .../prototype/toZonedDateTime/timezone-string.js | 15 +++++++++++++++ .../prototype/toZonedDateTime/timezone-string.js | 15 +++++++++++++++ .../Temporal/TimeZone/from/timezone-string.js | 13 +++++++++++++ .../ZonedDateTime/compare/timezone-string.js | 16 ++++++++++++++++ .../ZonedDateTime/from/timezone-string.js | 13 +++++++++++++ .../prototype/equals/timezone-string.js | 14 ++++++++++++++ .../prototype/since/timezone-string.js | 14 ++++++++++++++ .../prototype/until/timezone-string.js | 14 ++++++++++++++ .../prototype/withTimeZone/timezone-string.js | 15 +++++++++++++++ .../Temporal/ZonedDateTime/timezone-string.js | 13 +++++++++++++ 26 files changed, 377 insertions(+) create mode 100644 test/built-ins/Temporal/Duration/compare/timezone-string.js create mode 100644 test/built-ins/Temporal/Duration/prototype/add/timezone-string.js create mode 100644 test/built-ins/Temporal/Duration/prototype/round/timezone-string.js create mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/timezone-string.js create mode 100644 test/built-ins/Temporal/Duration/prototype/total/timezone-string.js create mode 100644 test/built-ins/Temporal/Instant/prototype/toString/timezone-string.js create mode 100644 test/built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-string.js create mode 100644 test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string.js create mode 100644 test/built-ins/Temporal/Now/plainDate/timezone-string.js create mode 100644 test/built-ins/Temporal/Now/plainDateISO/timezone-string.js create mode 100644 test/built-ins/Temporal/Now/plainDateTime/timezone-string.js create mode 100644 test/built-ins/Temporal/Now/plainDateTimeISO/timezone-string.js create mode 100644 test/built-ins/Temporal/Now/plainTimeISO/timezone-string.js create mode 100644 test/built-ins/Temporal/Now/zonedDateTime/timezone-string.js create mode 100644 test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-string.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-string.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-string.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-string.js create mode 100644 test/built-ins/Temporal/TimeZone/from/timezone-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/compare/timezone-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/timezone-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/since/timezone-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/until/timezone-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/timezone-string.js diff --git a/test/built-ins/Temporal/Duration/compare/timezone-string.js b/test/built-ins/Temporal/Duration/compare/timezone-string.js new file mode 100644 index 0000000000..fe1aa0c8a3 --- /dev/null +++ b/test/built-ins/Temporal/Duration/compare/timezone-string.js @@ -0,0 +1,14 @@ +// 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.duration.compare +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/timezone-string.js b/test/built-ins/Temporal/Duration/prototype/add/timezone-string.js new file mode 100644 index 0000000000..44448beab8 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/add/timezone-string.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.add +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1); + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/round/timezone-string.js b/test/built-ins/Temporal/Duration/prototype/round/timezone-string.js new file mode 100644 index 0000000000..a279c3cdea --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/timezone-string.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1); + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/timezone-string.js b/test/built-ins/Temporal/Duration/prototype/subtract/timezone-string.js new file mode 100644 index 0000000000..48dacac769 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/subtract/timezone-string.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.subtract +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1); + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/total/timezone-string.js b/test/built-ins/Temporal/Duration/prototype/total/timezone-string.js new file mode 100644 index 0000000000..9269225e56 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/total/timezone-string.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.total +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1); + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/toString/timezone-string.js b/test/built-ins/Temporal/Instant/prototype/toString/timezone-string.js new file mode 100644 index 0000000000..9c7ba8d863 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/timezone-string.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.tostring +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(0n); + +const result1 = instance.toString({ timeZone: "UTC" }); +assert.sameValue(result1.substr(-6), "+00:00", "Time zone created from string 'UTC'"); + +const result2 = instance.toString({ timeZone: "-01:30" }); +assert.sameValue(result2.substr(-6), "-01:30", "Time zone created from string '-01:30'"); diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-string.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-string.js new file mode 100644 index 0000000000..57f8c34c01 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-string.js @@ -0,0 +1,15 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.tozoneddatetime +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(0n); + +["UTC", "+01:30"].forEach((timeZone) => { + const result = instance.toZonedDateTime({ timeZone, calendar: "iso8601" }); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string.js new file mode 100644 index 0000000000..2dbecc39d4 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-string.js @@ -0,0 +1,15 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.tozoneddatetimeiso +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(0n); + +["UTC", "+01:30"].forEach((timeZone) => { + const result = instance.toZonedDateTimeISO(timeZone); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/Now/plainDate/timezone-string.js b/test/built-ins/Temporal/Now/plainDate/timezone-string.js new file mode 100644 index 0000000000..60aff45c34 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDate/timezone-string.js @@ -0,0 +1,14 @@ +// 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.now.plaindate +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + Temporal.Now.plainDate("iso8601", timeZone); +}); diff --git a/test/built-ins/Temporal/Now/plainDateISO/timezone-string.js b/test/built-ins/Temporal/Now/plainDateISO/timezone-string.js new file mode 100644 index 0000000000..d9a452e2df --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateISO/timezone-string.js @@ -0,0 +1,14 @@ +// 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.now.plaindateiso +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + Temporal.Now.plainDateISO(timeZone); +}); diff --git a/test/built-ins/Temporal/Now/plainDateTime/timezone-string.js b/test/built-ins/Temporal/Now/plainDateTime/timezone-string.js new file mode 100644 index 0000000000..1b4c0d10ec --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTime/timezone-string.js @@ -0,0 +1,14 @@ +// 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.now.plaindatetime +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + Temporal.Now.plainDateTime("iso8601", timeZone); +}); diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-string.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-string.js new file mode 100644 index 0000000000..a4aebae5a5 --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-string.js @@ -0,0 +1,14 @@ +// 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.now.plaindatetimeiso +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + Temporal.Now.plainDateTimeISO(timeZone); +}); diff --git a/test/built-ins/Temporal/Now/plainTimeISO/timezone-string.js b/test/built-ins/Temporal/Now/plainTimeISO/timezone-string.js new file mode 100644 index 0000000000..939f6afa0a --- /dev/null +++ b/test/built-ins/Temporal/Now/plainTimeISO/timezone-string.js @@ -0,0 +1,14 @@ +// 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.now.plaintimeiso +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +// The following are all valid strings so should not throw: + +["UTC", "+01:00"].forEach((timeZone) => { + Temporal.Now.plainTimeISO(timeZone); +}); diff --git a/test/built-ins/Temporal/Now/zonedDateTime/timezone-string.js b/test/built-ins/Temporal/Now/zonedDateTime/timezone-string.js new file mode 100644 index 0000000000..6e5e37ced6 --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTime/timezone-string.js @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.now.zoneddatetime +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +["UTC", "+01:30"].forEach((timeZone) => { + const result = Temporal.Now.zonedDateTime("iso8601", timeZone); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-string.js b/test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-string.js new file mode 100644 index 0000000000..f47fe6b3f7 --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-string.js @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.now.zoneddatetimeiso +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +["UTC", "+01:30"].forEach((timeZone) => { + const result = Temporal.Now.zonedDateTimeISO(timeZone); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-string.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-string.js new file mode 100644 index 0000000000..fe86a5ac07 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-string.js @@ -0,0 +1,15 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +["UTC", "+01:30"].forEach((timeZone) => { + const result = instance.toZonedDateTime(timeZone); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-string.js new file mode 100644 index 0000000000..4447e4492e --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-string.js @@ -0,0 +1,15 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tozoneddatetime +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2); + +["UTC", "+01:30"].forEach((timeZone) => { + const result = instance.toZonedDateTime(timeZone); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-string.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-string.js new file mode 100644 index 0000000000..0798d74080 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-string.js @@ -0,0 +1,15 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.tozoneddatetime +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(); + +["UTC", "+01:30"].forEach((timeZone) => { + const result = instance.toZonedDateTime({ plainDate: new Temporal.PlainDate(2000, 5, 2), timeZone }); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/TimeZone/from/timezone-string.js b/test/built-ins/Temporal/TimeZone/from/timezone-string.js new file mode 100644 index 0000000000..8be5cee002 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/from/timezone-string.js @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.from +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +["UTC", "+01:30"].forEach((timeZone) => { + const result = Temporal.TimeZone.from(timeZone); + assert.sameValue(result.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/timezone-string.js b/test/built-ins/Temporal/ZonedDateTime/compare/timezone-string.js new file mode 100644 index 0000000000..1a94c074a5 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/compare/timezone-string.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.compare +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +["UTC", "+01:30"].forEach((timeZone) => { + const epoch = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone(timeZone)); + + // These should be valid input and not throw + Temporal.ZonedDateTime.compare({ year: 2020, month: 5, day: 2, timeZone }, epoch); + Temporal.ZonedDateTime.compare(epoch, { year: 2020, month: 5, day: 2, timeZone }); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/timezone-string.js b/test/built-ins/Temporal/ZonedDateTime/from/timezone-string.js new file mode 100644 index 0000000000..c0736cd235 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/timezone-string.js @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +["UTC", "+01:30"].forEach((timeZone) => { + const result = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone }); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string.js new file mode 100644 index 0000000000..a8039bf329 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/timezone-string.js @@ -0,0 +1,14 @@ +// 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: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance1 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); +assert(instance1.equals({ year: 1970, month: 1, day: 1, timeZone: "UTC" }), "Time zone created from string 'UTC'"); + +const instance2 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("-01:30")); +assert(instance2.equals({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }), "Time zone created from string '-01:30'"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/timezone-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/timezone-string.js new file mode 100644 index 0000000000..39d985a818 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/timezone-string.js @@ -0,0 +1,14 @@ +// 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: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance1 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); +assert(instance1.since({ year: 1970, month: 1, day: 1, timeZone: "UTC" }).blank, "Time zone created from string 'UTC'"); + +const instance2 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("-01:30")); +assert(instance2.since({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }).blank, "Time zone created from string '-01:30'"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/timezone-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/timezone-string.js new file mode 100644 index 0000000000..24ff2b4ce2 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/timezone-string.js @@ -0,0 +1,14 @@ +// 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: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance1 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); +assert(instance1.until({ year: 1970, month: 1, day: 1, timeZone: "UTC" }).blank, "Time zone created from string 'UTC'"); + +const instance2 = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("-01:30")); +assert(instance2.until({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }).blank, "Time zone created from string '-01:30'"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-string.js new file mode 100644 index 0000000000..386dfb333d --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-string.js @@ -0,0 +1,15 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.withtimezone +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(0n, "UTC"); + +["UTC", "+01:30"].forEach((timeZone) => { + const result = instance.withTimeZone(timeZone); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/timezone-string.js b/test/built-ins/Temporal/ZonedDateTime/timezone-string.js new file mode 100644 index 0000000000..95d96b58d5 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/timezone-string.js @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime +description: Time zone IDs are valid input for a time zone +features: [Temporal] +---*/ + +["UTC", "+01:30"].forEach((timeZone) => { + const result = new Temporal.ZonedDateTime(0n, timeZone); + assert.sameValue(result.timeZone.id, timeZone, `Time zone created from string "${timeZone}"`); +});