| 1 |
// |reftest| skip-if(winWidget||!xulRuntime.shell||!this.hasOwnProperty("Intl")) |
| 2 |
|
| 3 |
assertEq(/^(PST|PDT)$/.test(getTimeZone()), true, |
| 4 |
"The default time zone is set to PST8PDT for all jstests (when run in the shell)"); |
| 5 |
|
| 6 |
function timeZoneName() { |
| 7 |
var dtf = new Intl.DateTimeFormat("en-US", {timeZoneName: "long"}); |
| 8 |
return dtf.formatToParts(Date.UTC(2017, 2, 31, 12, 0, 0)).filter(x => x.type === "timeZoneName")[0].value; |
| 9 |
} |
| 10 |
|
| 11 |
setTimeZone("Europe/Paris"); |
| 12 |
assertEq(timeZoneName(), "Central European Summer Time"); |
| 13 |
|
| 14 |
setTimeZone(":Europe/Helsinki"); |
| 15 |
assertEq(timeZoneName(), "Eastern European Summer Time"); |
| 16 |
|
| 17 |
setTimeZone("/zoneinfo/America/Chicago"); |
| 18 |
assertEq(timeZoneName(), "Central Daylight Time"); |
| 19 |
|
| 20 |
setTimeZone("/this-part-is-ignored/zoneinfo/America/Chicago"); |
| 21 |
assertEq(timeZoneName(), "Central Daylight Time"); |
| 22 |
|
| 23 |
setTimeZone(":/this-part-is-ignored/zoneinfo/America/Phoenix"); |
| 24 |
assertEq(timeZoneName(), "Mountain Standard Time"); |
| 25 |
|
| 26 |
const invalidTimeZones = [ |
| 27 |
// Non-existent timezone |
| 28 |
"foo", |
| 29 |
"/zoneinfo/foo", |
| 30 |
"/zoneinfo/", |
| 31 |
|
| 32 |
// Not capitalized |
| 33 |
"america/chicago", |
| 34 |
|
| 35 |
// No leading / |
| 36 |
"zoneinfo/America/Chicago", |
| 37 |
"foo/zoneinfo/America/Chicago", |
| 38 |
":zoneinfo/America/Chicago", |
| 39 |
":foo/zoneinfo/America/Chicago", |
| 40 |
|
| 41 |
// Path without "/zoneinfo/" |
| 42 |
"/foo/America/Chicago", |
| 43 |
":/foo/America/Chicago", |
| 44 |
|
| 45 |
// Two colons |
| 46 |
"::Europe/London", |
| 47 |
"::/zoneinfo/America/Los_Angeles", |
| 48 |
"::/this-part-is-ignored/zoneinfo/America/Los_Angeles", |
| 49 |
]; |
| 50 |
|
| 51 |
for (const invalid of invalidTimeZones) { |
| 52 |
assertThrowsInstanceOf(() => setTimeZone(invalid), Error); |
| 53 |
} |
| 54 |
|
| 55 |
if (typeof reportCompare === "function") |
| 56 |
reportCompare(true, true); |