mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 05:55:36 +02:00
Fix existing tests broken by proposal-canonical-tz
This commit is contained in:
parent
a5e2cf2433
commit
5d261f3641
@ -1,35 +0,0 @@
|
|||||||
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
es5id: 6.4_c
|
|
||||||
description: >
|
|
||||||
Tests that additional time zone names, if accepted, are handled
|
|
||||||
correctly.
|
|
||||||
author: Norbert Lindenberg
|
|
||||||
---*/
|
|
||||||
|
|
||||||
// canonicalization specified in conformance clause
|
|
||||||
var additionalTimeZoneNames = {
|
|
||||||
"Etc/GMT": "UTC",
|
|
||||||
"Greenwich": "UTC",
|
|
||||||
"PRC": "Asia/Shanghai",
|
|
||||||
"AmErIcA/LoS_aNgElEs": "America/Los_Angeles",
|
|
||||||
"etc/gmt+7": "Etc/GMT+7"
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.getOwnPropertyNames(additionalTimeZoneNames).forEach(function (name) {
|
|
||||||
var format, error;
|
|
||||||
try {
|
|
||||||
format = new Intl.DateTimeFormat([], {timeZone: name});
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (error === undefined) {
|
|
||||||
var actual = format.resolvedOptions().timeZone;
|
|
||||||
var expected = additionalTimeZoneNames[name];
|
|
||||||
assert.sameValue(actual, expected, "Time zone name " + name + " was accepted, but incorrectly canonicalized.");
|
|
||||||
} else {
|
|
||||||
assert(error instanceof RangeError, "Time zone name " + name + " was rejected with wrong error " + error.name + ".");
|
|
||||||
}
|
|
||||||
});
|
|
@ -11,8 +11,11 @@ const valid = [
|
|||||||
["Europe/Vienna"],
|
["Europe/Vienna"],
|
||||||
["America/New_York"],
|
["America/New_York"],
|
||||||
["Africa/CAIRO", "Africa/Cairo"],
|
["Africa/CAIRO", "Africa/Cairo"],
|
||||||
["Asia/Ulan_Bator", "Asia/Ulaanbaatar"],
|
["africa/cairo", "Africa/Cairo"],
|
||||||
["GMT", "UTC"],
|
["Asia/Ulaanbaatar"],
|
||||||
|
["Asia/Ulan_Bator"],
|
||||||
|
["UTC"],
|
||||||
|
["GMT"]
|
||||||
];
|
];
|
||||||
for (const [zone, id = zone] of valid) {
|
for (const [zone, id = zone] of valid) {
|
||||||
const result = new Temporal.TimeZone(zone);
|
const result = new Temporal.TimeZone(zone);
|
||||||
|
@ -9,13 +9,7 @@ features: [Temporal]
|
|||||||
|
|
||||||
// "Etc/GMT-0" through "Etc/GMT-14" are OK
|
// "Etc/GMT-0" through "Etc/GMT-14" are OK
|
||||||
|
|
||||||
assert.sameValue(
|
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14].forEach((n) => {
|
||||||
(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,13,14].forEach((n) => {
|
|
||||||
let tz = "Etc/GMT-" + n;
|
let tz = "Etc/GMT-" + n;
|
||||||
let instance = new Temporal.TimeZone(tz);
|
let instance = new Temporal.TimeZone(tz);
|
||||||
assert.sameValue(
|
assert.sameValue(
|
||||||
@ -54,14 +48,7 @@ assert.throws(
|
|||||||
|
|
||||||
// Etc/GMT+0" through "Etc/GMT+12" are OK
|
// Etc/GMT+0" through "Etc/GMT+12" are OK
|
||||||
|
|
||||||
// zero is handled in its own way (say "UTC" rather than "GMT"):
|
[0,1,2,3,4,5,6,7,8,9,10,11,12].forEach((n) => {
|
||||||
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) => {
|
|
||||||
let tz = "Etc/GMT+" + n;
|
let tz = "Etc/GMT+" + n;
|
||||||
let instance = new Temporal.TimeZone(tz);
|
let instance = new Temporal.TimeZone(tz);
|
||||||
assert.sameValue(
|
assert.sameValue(
|
||||||
|
@ -13,9 +13,9 @@ const valids = [
|
|||||||
["Europe/Vienna"],
|
["Europe/Vienna"],
|
||||||
["America/New_York"],
|
["America/New_York"],
|
||||||
["Africa/CAIRO", "Africa/Cairo"],
|
["Africa/CAIRO", "Africa/Cairo"],
|
||||||
["Asia/Ulan_Bator", "Asia/Ulaanbaatar"],
|
["Asia/Ulan_Bator"],
|
||||||
["GMT", "UTC"],
|
["GMT"],
|
||||||
["etc/gmt", "UTC"],
|
["etc/gmt", "Etc/GMT"],
|
||||||
["1994-11-05T08:15:30-05:00[America/New_York]", "America/New_York"],
|
["1994-11-05T08:15:30-05:00[America/New_York]", "America/New_York"],
|
||||||
["1994-11-05T08:15:30-05[America/New_York]", "America/New_York"],
|
["1994-11-05T08:15:30-05[America/New_York]", "America/New_York"],
|
||||||
["1994-11-05T08:15:30\u221205:00[America/New_York]", "America/New_York"],
|
["1994-11-05T08:15:30\u221205:00[America/New_York]", "America/New_York"],
|
||||||
|
@ -9,13 +9,7 @@ features: [Temporal]
|
|||||||
|
|
||||||
// "Etc/GMT-0" through "Etc/GMT-14" are OK
|
// "Etc/GMT-0" through "Etc/GMT-14" are OK
|
||||||
|
|
||||||
assert.sameValue(
|
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].forEach((n) => {
|
||||||
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 tz = "Etc/GMT-" + n;
|
||||||
const instance = Temporal.TimeZone.from(tz);
|
const instance = Temporal.TimeZone.from(tz);
|
||||||
assert.sameValue(
|
assert.sameValue(
|
||||||
@ -52,14 +46,7 @@ assert.throws(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Etc/GMT+0" through "Etc/GMT+12" are OK
|
// "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) => {
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].forEach((n) => {
|
||||||
const tz = "Etc/GMT+" + n;
|
const tz = "Etc/GMT+" + n;
|
||||||
|
@ -8,17 +8,17 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const legacyNames = [
|
const legacyNames = [
|
||||||
["Etc/GMT0", "UTC"],
|
"Etc/GMT0",
|
||||||
["GMT0", "UTC"],
|
"GMT0",
|
||||||
["GMT-0", "UTC"],
|
"GMT-0",
|
||||||
["GMT+0", "UTC"],
|
"GMT+0",
|
||||||
["EST5EDT", "EST5EDT"],
|
"EST5EDT",
|
||||||
["CST6CDT", "CST6CDT"],
|
"CST6CDT",
|
||||||
["MST7MDT", "MST7MDT"],
|
"MST7MDT",
|
||||||
["PST8PDT", "PST8PDT"],
|
"PST8PDT"
|
||||||
];
|
];
|
||||||
|
|
||||||
legacyNames.forEach(([arg, expectedID]) => {
|
legacyNames.forEach((arg) => {
|
||||||
const tz = Temporal.TimeZone.from(arg);
|
const tz = Temporal.TimeZone.from(arg);
|
||||||
assert.sameValue(tz.toString(), expectedID, `"${arg}" is a supported name for the "${expectedID}" time zone`);
|
assert.sameValue(tz.toString(), arg, `"${arg}" does not match "${tz.toString()}" time zone identifier`);
|
||||||
});
|
});
|
||||||
|
@ -8,17 +8,17 @@ features: [Temporal]
|
|||||||
---*/
|
---*/
|
||||||
|
|
||||||
const legacyNames = [
|
const legacyNames = [
|
||||||
["Etc/GMT0", "UTC"],
|
"Etc/GMT0",
|
||||||
["GMT0", "UTC"],
|
"GMT0",
|
||||||
["GMT-0", "UTC"],
|
"GMT-0",
|
||||||
["GMT+0", "UTC"],
|
"GMT+0",
|
||||||
["EST5EDT", "EST5EDT"],
|
"EST5EDT",
|
||||||
["CST6CDT", "CST6CDT"],
|
"CST6CDT",
|
||||||
["MST7MDT", "MST7MDT"],
|
"MST7MDT",
|
||||||
["PST8PDT", "PST8PDT"],
|
"PST8PDT"
|
||||||
];
|
];
|
||||||
|
|
||||||
legacyNames.forEach(([arg, expectedID]) => {
|
legacyNames.forEach((arg) => {
|
||||||
const tz = new Temporal.TimeZone(arg);
|
const tz = new Temporal.TimeZone(arg);
|
||||||
assert.sameValue(tz.toString(), expectedID, `"${arg}" is a supported name for the "${expectedID}" time zone`);
|
assert.sameValue(tz.toString(), arg, `"${arg}" does not match "${tz.toString()}" time zone identifier`);
|
||||||
});
|
});
|
||||||
|
@ -49,6 +49,6 @@ const testCases = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (let id of testCases) {
|
for (let id of testCases) {
|
||||||
// Doesn't throw a RangeError.
|
const tz = new Temporal.TimeZone(id);
|
||||||
new Temporal.TimeZone(id);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,6 @@ const testCases = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (let id of testCases) {
|
for (let id of testCases) {
|
||||||
// Doesn't throw a RangeError.
|
const tz = new Temporal.TimeZone(id);
|
||||||
new Temporal.TimeZone(id);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,6 @@ const testCases = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (let id of testCases) {
|
for (let id of testCases) {
|
||||||
// Doesn't throw a RangeError.
|
const tz = new Temporal.TimeZone(id);
|
||||||
new Temporal.TimeZone(id);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,6 @@ const testCases = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (let id of testCases) {
|
for (let id of testCases) {
|
||||||
// Doesn't throw a RangeError.
|
const tz = new Temporal.TimeZone(id);
|
||||||
new Temporal.TimeZone(id);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,6 @@ const testCases = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (let id of testCases) {
|
for (let id of testCases) {
|
||||||
// Doesn't throw a RangeError.
|
const tz = new Temporal.TimeZone(id);
|
||||||
new Temporal.TimeZone(id);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,6 @@ const testCases = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (let id of testCases) {
|
for (let id of testCases) {
|
||||||
// Doesn't throw a RangeError.
|
const tz = new Temporal.TimeZone(id);
|
||||||
new Temporal.TimeZone(id);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ const testCases = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (let id of testCases) {
|
for (let id of testCases) {
|
||||||
// Doesn't throw a RangeError.
|
const tz = new Temporal.TimeZone(id);
|
||||||
new Temporal.TimeZone(id);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,6 @@ const testCases = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (let id of testCases) {
|
for (let id of testCases) {
|
||||||
// Doesn't throw a RangeError.
|
const tz = new Temporal.TimeZone(id);
|
||||||
new Temporal.TimeZone(id);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
@ -8,20 +8,20 @@ description: >
|
|||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const testCases = {
|
const testCases = [
|
||||||
"Etc/GMT": "UTC",
|
"Etc/GMT",
|
||||||
"Etc/GMT+0": "UTC",
|
"Etc/GMT+0",
|
||||||
"Etc/GMT-0": "UTC",
|
"Etc/GMT-0",
|
||||||
"Etc/GMT0": "UTC",
|
"Etc/GMT0",
|
||||||
"Etc/Greenwich": "UTC",
|
"Etc/Greenwich",
|
||||||
"Etc/UCT": "UTC",
|
"Etc/UCT",
|
||||||
"Etc/UTC": "UTC",
|
"Etc/UTC",
|
||||||
"Etc/Universal": "UTC",
|
"Etc/Universal",
|
||||||
"Etc/Zulu": "UTC",
|
"Etc/Zulu",
|
||||||
};
|
];
|
||||||
|
|
||||||
for (let [id, canonical] of Object.entries(testCases)) {
|
for (let id of testCases) {
|
||||||
let tz = new Temporal.TimeZone(id);
|
let tz = new Temporal.TimeZone(id);
|
||||||
|
|
||||||
assert.sameValue(tz.id, canonical);
|
assert.sameValue(tz.id, id);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user