From 0dec11d949392014f2ce3180bf3fd4183b9af6cc Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 18 Oct 2021 20:38:11 -0700 Subject: [PATCH] Test positive and negative offset time zones in FormatTimeZoneOffset Tests for the normative change made to Temporal in https://github.com/tc39/proposal-temporal/pull/1833 --- .../prototype/toString/timezone-offset.js | 19 +++++++++++++++++++ .../prototype/getOffsetStringFor/basic.js | 19 +++++++++++++++++++ .../prototype/getISOFields/offset.js | 19 +++++++++++++++++++ .../ZonedDateTime/prototype/offset/basic.js | 18 ++++++++++++++++++ .../ZonedDateTime/prototype/toJSON/offset.js | 18 ++++++++++++++++++ .../prototype/toString/offset.js | 18 ++++++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 test/built-ins/Temporal/Instant/prototype/toString/timezone-offset.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/basic.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/getISOFields/offset.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/offset/basic.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/offset.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/toString/offset.js diff --git a/test/built-ins/Temporal/Instant/prototype/toString/timezone-offset.js b/test/built-ins/Temporal/Instant/prototype/toString/timezone-offset.js new file mode 100644 index 0000000000..1914167cf0 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/timezone-offset.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 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: The time zone offset part of the string serialization +features: [BigInt, Temporal] +---*/ + +const instant = new Temporal.Instant(0n); + +function test(timeZoneIdentifier, expected, description) { + const timeZone = new Temporal.TimeZone(timeZoneIdentifier); + assert.sameValue(instant.toString({ timeZone }), expected, description); +} + +test("UTC", "1970-01-01T00:00:00+00:00", "offset of UTC is +00:00"); +test("+01:00", "1970-01-01T01:00:00+01:00", "positive offset"); +test("-05:00", "1969-12-31T19:00:00-05:00", "negative offset"); diff --git a/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/basic.js b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/basic.js new file mode 100644 index 0000000000..184bb12a20 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/basic.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 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: Basic tests for Temporal.TimeZone.prototype.getOffsetStringFor +features: [BigInt, Temporal] +---*/ + +const instant = new Temporal.Instant(0n); + +function test(timeZoneIdentifier, expectedOffsetString, description) { + const timeZone = new Temporal.TimeZone(timeZoneIdentifier); + assert.sameValue(timeZone.getOffsetStringFor(instant), expectedOffsetString, description); +} + +test("UTC", "+00:00", "offset of UTC is +00:00"); +test("+01:00", "+01:00", "positive offset"); +test("-05:00", "-05:00", "negative offset"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/getISOFields/offset.js b/test/built-ins/Temporal/ZonedDateTime/prototype/getISOFields/offset.js new file mode 100644 index 0000000000..96fa20c61f --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/getISOFields/offset.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.getisofields +description: The offset property of returned object +features: [BigInt, Temporal] +---*/ + +function test(timeZoneIdentifier, expectedOffsetString, description) { + const timeZone = new Temporal.TimeZone(timeZoneIdentifier); + const datetime = new Temporal.ZonedDateTime(0n, timeZone); + const fields = datetime.getISOFields(); + assert.sameValue(fields.offset, expectedOffsetString, description); +} + +test("UTC", "+00:00", "offset of UTC is +00:00"); +test("+01:00", "+01:00", "positive offset"); +test("-05:00", "-05:00", "negative offset"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/offset/basic.js b/test/built-ins/Temporal/ZonedDateTime/prototype/offset/basic.js new file mode 100644 index 0000000000..6c104323ed --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/offset/basic.js @@ -0,0 +1,18 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.zoneddatetime.prototype.offset +description: Basic tests for Temporal.ZonedDateTime.prototype.offset +features: [BigInt, Temporal] +---*/ + +function test(timeZoneIdentifier, expectedOffsetString, description) { + const timeZone = new Temporal.TimeZone(timeZoneIdentifier); + const datetime = new Temporal.ZonedDateTime(0n, timeZone); + assert.sameValue(datetime.offset, expectedOffsetString, description); +} + +test("UTC", "+00:00", "offset of UTC is +00:00"); +test("+01:00", "+01:00", "positive offset"); +test("-05:00", "-05:00", "negative offset"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/offset.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/offset.js new file mode 100644 index 0000000000..e3246b9946 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/offset.js @@ -0,0 +1,18 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.tojson +description: The time zone offset part of the string serialization +features: [BigInt, Temporal] +---*/ + +function test(timeZoneIdentifier, expected, description) { + const timeZone = new Temporal.TimeZone(timeZoneIdentifier); + const datetime = new Temporal.ZonedDateTime(0n, timeZone); + assert.sameValue(datetime.toJSON(), expected, description); +} + +test("UTC", "1970-01-01T00:00:00+00:00[UTC]", "offset of UTC is +00:00"); +test("+01:00", "1970-01-01T01:00:00+01:00[+01:00]", "positive offset"); +test("-05:00", "1969-12-31T19:00:00-05:00[-05:00]", "negative offset"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/offset.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/offset.js new file mode 100644 index 0000000000..5ff25b6c71 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/offset.js @@ -0,0 +1,18 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.tostring +description: The time zone offset part of the string serialization +features: [BigInt, Temporal] +---*/ + +function test(timeZoneIdentifier, expected, description) { + const timeZone = new Temporal.TimeZone(timeZoneIdentifier); + const datetime = new Temporal.ZonedDateTime(0n, timeZone); + assert.sameValue(datetime.toString(), expected, description); +} + +test("UTC", "1970-01-01T00:00:00+00:00[UTC]", "offset of UTC is +00:00"); +test("+01:00", "1970-01-01T01:00:00+01:00[+01:00]", "positive offset"); +test("-05:00", "1969-12-31T19:00:00-05:00[-05:00]", "negative offset");