Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check a variety of offset Etc/GMT timezones #3403

Merged
merged 5 commits into from
Mar 30, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions test/intl402/Temporal/TimeZone/etc-timezone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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
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(
(new Temporal.TimeZone("Etc/GMT-0")).toString(),
jessealama marked this conversation as resolved.
Show resolved Hide resolved
"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) => {
let tz = "Etc/GMT-" + n;
let instance = new Temporal.TimeZone(tz);
assert.sameValue(
instance.toString(),
tz,
tz + " is a valid timezone"
);
});

let gmtMinus15TZ = "Etc/GMT-15";
assert.throws(
RangeError,
() => { new Temporal.TimeZone(gmtMinus15TZ); },
gmtMinus15TZ + " is an invalid timezone"
);
jessealama marked this conversation as resolved.
Show resolved Hide resolved

// "Etc/GMT-0N" is not OK (1 ≤ N ≤ 9)
[1,2,3,4,5,6,7,8,9].forEach((n) => {
let tz = "Etc/GMT-0" + n;
assert.throws(
RangeError,
() => { new Temporal.TimeZone(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) => {
let tz = "Etc/GMT+0" + n;
assert.throws(
RangeError,
() => { new Temporal.TimeZone(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(
(new Temporal.TimeZone("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) => {
jessealama marked this conversation as resolved.
Show resolved Hide resolved
let tz = "Etc/GMT+" + n;
let instance = new Temporal.TimeZone(tz);
assert.sameValue(
instance.toString(),
tz,
tz + " is a valid timezone"
);
});

// "Etc/GMT+13" is not OK

let gmtPlus13TZ = "Etc/GMT+13";
assert.throws(
RangeError,
() => { new Temporal.TimeZone(gmtPlus13TZ); },
gmtPlus13TZ + " is an invalid timezone"
);
jessealama marked this conversation as resolved.
Show resolved Hide resolved