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
This commit is contained in:
Philip Chimento 2021-10-18 20:38:11 -07:00 committed by Rick Waldron
parent 615408bc60
commit 0dec11d949
6 changed files with 111 additions and 0 deletions

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");