Temporal: Perform TimeZone 'Etc/GMT±NN' tests for from() as well

The Etc/GMT±... time zones should be accepted in from() as well as the
TimeZone constructor. Previously this was not the case for +0 and -0 due
to those being IANA legacy names.

This basically copies the existing test file for the TimeZone constructor,
and performs the same tests for TimeZone.from().

See https://github.com/tc39/proposal-temporal/pull/2292 which is a
normative change that achieved consensus at the July 2022 TC39 meeting.
This commit is contained in:
Philip Chimento 2022-07-26 11:05:53 -07:00 committed by Philip Chimento
parent 6fa1bb89a3
commit 5cb596f191
1 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,79 @@
// 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: Some Etc/GMT{+/-}{0}N timezones are valid, but not all
features: [Temporal]
---*/
// "Etc/GMT-0" through "Etc/GMT-14" are OK
assert.sameValue(
Temporal.TimeZone.from("Etc/GMT-0").toString(),
"UTC", // if the offset is -0, we say "UTC" rather than "GMT"
"Etc/GMT-0 is a valid timezone"
);
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].forEach((n) => {
const tz = "Etc/GMT-" + n;
const instance = Temporal.TimeZone.from(tz);
assert.sameValue(
instance.toString(),
tz,
tz + " is a valid timezone"
);
});
const gmtMinus24TZ = "Etc/GMT-24";
assert.throws(
RangeError,
() => Temporal.TimeZone.from(gmtMinus24TZ),
gmtMinus24TZ + " is an invalid timezone"
);
// "Etc/GMT-0N" is not OK (1 ≤ N ≤ 9)
[1, 2, 3, 4, 5, 6, 7, 8, 9].forEach((n) => {
const tz = "Etc/GMT-0" + n;
assert.throws(
RangeError,
() => Temporal.TimeZone.from(tz),
tz + " is an invalid timezone"
);
});
// "Etc/GMT+0N" is not OK (0 ≤ N ≤ 9)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].forEach((n) => {
const tz = "Etc/GMT+0" + n;
assert.throws(
RangeError,
() => Temporal.TimeZone.from(tz),
tz + " is an invalid timezone"
);
});
// Etc/GMT+0" through "Etc/GMT+12" are OK
// zero is handled in its own way (say "UTC" rather than "GMT"):
assert.sameValue(
Temporal.TimeZone.from("Etc/GMT+0").toString(),
"UTC", // if the offset is +0, we say "UTC" rather than "GMT"
"Etc/GMT+0 is a valid timezone"
);
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].forEach((n) => {
const tz = "Etc/GMT+" + n;
const instance = Temporal.TimeZone.from(tz);
assert.sameValue(
instance.toString(),
tz,
tz + " is a valid timezone"
);
});
const gmtPlus24TZ = "Etc/GMT+24";
assert.throws(
RangeError,
() => Temporal.TimeZone.from(gmtPlus24TZ),
gmtPlus24TZ + " is an invalid timezone"
);