Skip to content

Commit

Permalink
Bug 1930466 - Part 1: Use zone.tab to guide time zone canonicalisatio…
Browse files Browse the repository at this point in the history
…n. r=dminor

Implement the changes from <tc39/ecma402#877> to reduce
differences in time zone canonicalisation when compared to V8 and JSC (which
both use CLDR time zone data instead of IANA time zone data).

Implementing the `AvailableNamedTimeZoneIdentifiers` spec operation requires to
link time zone identifiers to region codes. When the time zone is listed in the
"zone.tab" file, we can get the region code from "zone.tab". In all other cases
we need to manually map the time zone to a matching region, because CLDR doesn't
have "public" data for this [1]. This is implemented using the new file
"intl/TimeZoneMapping.yaml".

ICU 74 added `ucal_getIanaTimeZoneID` to get the canonical IANA time zone id.
Internally `ucal_getIanaTimeZoneID` first calls `ucal_getCanonicalTimeZoneID`
and then loads a resource bundle to check if there are any time zone ids which
need to be replaced with other ids for compatibility with IANA data. Unfortunately
the resource bundle is not cached, so calling `ucal_getIanaTimeZoneID` instead
of `ucal_getIanaTimeZoneID` adds a considerable performance overhead. To avoid
any performance regressions, we keep our own time zone rewriting code for the
time being.

Using our own code also means we don't have to add a workaround for this CLDR
bug: <https://unicode-org.atlassian.net/browse/CLDR-16439>.

Also remove "Factory" from the list of supported time zone identifiers, because
supporting it was always a bit questionable and latest V8 also doesn't support
it anymore, so we shouldn't run into web-compat issues.

Remove the old generated tests and add "timeZone_links.js" to ensure time zone
links are correctly resolved.

[1] Neither of these two files look like "public" data to me:
- https://github.com/unicode-org/cldr/blob/main/tools/cldr-code/src/main/resources/org/unicode/cldr/util/data/TZID.txt
- https://github.com/unicode-org/cldr/blob/main/tools/cldr-code/src/main/resources/org/unicode/cldr/icu/idList.txt

Differential Revision: https://phabricator.services.mozilla.com/D228584

UltraBlame original commit: 880f2288640c43653f56bc919e9d16434426bf84
  • Loading branch information
marco-c committed Dec 1, 2024
1 parent 293c903 commit b189cde
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 596 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
async function verifySpoofed() {
ok(true, "Running on " + content.location.origin);

SpecialPowers.Cu.getJSTestingFunctions().setTimeZone("PST8PDT");
SpecialPowers.Cu.getJSTestingFunctions().setTimeZone("America/Los_Angeles");
is(
Intl.DateTimeFormat("en-US").resolvedOptions().timeZone,
"PST8PDT",
"America/Los_Angeles",
"Default time zone should have changed"
);

Expand Down Expand Up @@ -113,10 +113,10 @@ add_task(async function test_timezone_exempt() {
});

await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
SpecialPowers.Cu.getJSTestingFunctions().setTimeZone("PST8PDT");
SpecialPowers.Cu.getJSTestingFunctions().setTimeZone("America/Los_Angeles");
is(
Intl.DateTimeFormat("en-US").resolvedOptions().timeZone,
"PST8PDT",
"America/Los_Angeles",
"Default time zone should have changed"
);

Expand All @@ -129,7 +129,7 @@ add_task(async function test_timezone_exempt() {

is(
Intl.DateTimeFormat("en-US").resolvedOptions().timeZone,
"PST8PDT",
"America/Los_Angeles",
"Content should use default time zone"
);
}
Expand Down Expand Up @@ -169,10 +169,10 @@ add_task(async function test_timezone_exempt_wrong_domain() {
});

add_task(async function test_timezone_exmpt_browser() {
SpecialPowers.Cu.getJSTestingFunctions().setTimeZone("PST8PDT");
SpecialPowers.Cu.getJSTestingFunctions().setTimeZone("America/Los_Angeles");
is(
Intl.DateTimeFormat("en-US").resolvedOptions().timeZone,
"PST8PDT",
"America/Los_Angeles",
"Default time zone should have changed"
);

Expand All @@ -182,7 +182,7 @@ add_task(async function test_timezone_exmpt_browser() {

is(
Intl.DateTimeFormat("en-US").resolvedOptions().timeZone,
"PST8PDT",
"America/Los_Angeles",
"Timezone in chrome should be unaffected by resistFingerprinting"
);

Expand All @@ -196,7 +196,7 @@ add_task(async function test_timezone_exmpt_browser() {

is(
newWindow.Intl.DateTimeFormat("en-US").resolvedOptions().timeZone,
"PST8PDT",
"America/Los_Angeles",
"Timezone in new chrome window should be unaffected by resistFingerprinting"
);

Expand Down
70 changes: 25 additions & 45 deletions js/src/builtin/intl/TimeZoneDataGenerated.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,25 @@ namespace timezone {

const char* const ianaZonesTreatedAsLinksByICU[] = {
"Africa/Asmara",
"Africa/Timbuktu",
"America/Argentina/Buenos_Aires",
"America/Argentina/Catamarca",
"America/Argentina/ComodRivadavia",
"America/Argentina/Cordoba",
"America/Argentina/Jujuy",
"America/Argentina/Mendoza",
"America/Atikokan",
"America/Ensenada",
"America/Indiana/Indianapolis",
"America/Kentucky/Louisville",
"America/Montreal",
"America/Nipigon",
"America/Nuuk",
"America/Pangnirtung",
"America/Rainy_River",
"America/Rosario",
"America/Thunder_Bay",
"America/Yellowknife",
"Asia/Chongqing",
"Asia/Harbin",
"Asia/Ho_Chi_Minh",
"Asia/Kashgar",
"Asia/Kathmandu",
"Asia/Kolkata",
"Asia/Tel_Aviv",
"Asia/Yangon",
"Atlantic/Faroe",
"Atlantic/Jan_Mayen",
"Australia/Currie",
"CET",
"CST6CDT",
"EET",
"EST",
"EST5EDT",
"Europe/Belfast",
"Europe/Kyiv",
"Europe/Tiraspol",
"Europe/Uzhgorod",
"Europe/Zaporozhye",
"Factory",
"HST",
"MET",
"MST",
"MST7MDT",
"PST8PDT",
"Pacific/Chuuk",
"Pacific/Johnston",
"Pacific/Kanton",
"Pacific/Pohnpei",
"WET",
"UTC",
};


Expand All @@ -74,38 +42,49 @@ struct LinkAndTarget

const LinkAndTarget ianaLinksCanonicalizedDifferentlyByICU[] = {
{ "Africa/Asmera", "Africa/Asmara" },
{ "America/Argentina/ComodRivadavia", "America/Argentina/Catamarca" },
{ "America/Buenos_Aires", "America/Argentina/Buenos_Aires" },
{ "America/Catamarca", "America/Argentina/Catamarca" },
{ "America/Coral_Harbour", "America/Atikokan" },
{ "America/Cordoba", "America/Argentina/Cordoba" },
{ "America/Fort_Wayne", "America/Indiana/Indianapolis" },
{ "America/Godthab", "America/Nuuk" },
{ "America/Indianapolis", "America/Indiana/Indianapolis" },
{ "America/Jujuy", "America/Argentina/Jujuy" },
{ "America/Kralendijk", "America/Curacao" },
{ "America/Louisville", "America/Kentucky/Louisville" },
{ "America/Lower_Princes", "America/Curacao" },
{ "America/Marigot", "America/Port_of_Spain" },
{ "America/Mendoza", "America/Argentina/Mendoza" },
{ "America/St_Barthelemy", "America/Port_of_Spain" },
{ "America/Rosario", "America/Argentina/Cordoba" },
{ "Antarctica/South_Pole", "Antarctica/McMurdo" },
{ "Arctic/Longyearbyen", "Europe/Oslo" },
{ "Asia/Calcutta", "Asia/Kolkata" },
{ "Asia/Chungking", "Asia/Chongqing" },
{ "Asia/Katmandu", "Asia/Kathmandu" },
{ "Asia/Rangoon", "Asia/Yangon" },
{ "Asia/Saigon", "Asia/Ho_Chi_Minh" },
{ "Atlantic/Faeroe", "Atlantic/Faroe" },
{ "Europe/Bratislava", "Europe/Prague" },
{ "Europe/Busingen", "Europe/Zurich" },
{ "Etc/GMT", "UTC" },
{ "Etc/GMT+0", "UTC" },
{ "Etc/GMT-0", "UTC" },
{ "Etc/GMT0", "UTC" },
{ "Etc/Greenwich", "UTC" },
{ "Etc/UCT", "UTC" },
{ "Etc/UTC", "UTC" },
{ "Etc/Universal", "UTC" },
{ "Etc/Zulu", "UTC" },
{ "Europe/Kiev", "Europe/Kyiv" },
{ "Europe/Mariehamn", "Europe/Helsinki" },
{ "Europe/Podgorica", "Europe/Belgrade" },
{ "Europe/San_Marino", "Europe/Rome" },
{ "Europe/Vatican", "Europe/Rome" },
{ "Europe/Uzhgorod", "Europe/Kyiv" },
{ "Europe/Zaporozhye", "Europe/Kyiv" },
{ "GMT", "UTC" },
{ "GMT+0", "UTC" },
{ "GMT-0", "UTC" },
{ "GMT0", "UTC" },
{ "Greenwich", "UTC" },
{ "Pacific/Enderbury", "Pacific/Kanton" },
{ "Pacific/Ponape", "Pacific/Pohnpei" },
{ "Pacific/Truk", "Pacific/Chuuk" },
{ "Pacific/Yap", "Pacific/Chuuk" },
{ "UCT", "UTC" },
{ "US/East-Indiana", "America/Indiana/Indianapolis" },
{ "Universal", "UTC" },
{ "Zulu", "UTC" },
};


Expand Down Expand Up @@ -139,6 +118,7 @@ const char* const legacyICUTimeZones[] = {
"SST",
"US/Pacific-New",
"VST",
"Factory",
"SystemV/AST4",
"SystemV/AST4ADT",
"SystemV/CST6",
Expand Down
157 changes: 157 additions & 0 deletions js/src/builtin/intl/TimeZoneMapping.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Provide mapping from time zone identifiers to region codes for time zones
# which aren't listed in tzdata's zone.tab file.

Africa/Timbuktu: ML
Africa/Asmera: ER

America/Argentina/ComodRivadavia: AR
America/Atka: US
America/Buenos_Aires: AR
America/Catamarca: AR
America/Coral_Harbour: CA
America/Cordoba: AR
America/Ensenada: MX
America/Fort_Wayne: US
America/Godthab: GL
America/Indianapolis: US
America/Jujuy: AR
America/Knox_IN: US
America/Louisville: US
America/Mendoza: AR
America/Montreal: CA
America/Nipigon: CA
America/Pangnirtung: CA
America/Porto_Acre: BR
America/Rainy_River: CA
America/Rosario: AR
America/Santa_Isabel: MX
America/Shiprock: US
America/Thunder_Bay: CA
America/Virgin: VI
America/Yellowknife: CA

Antarctica/South_Pole: AQ

Asia/Choibalsan: MN
Asia/Chongqing: CN
Asia/Harbin: CN
Asia/Kashgar: CN
Asia/Tel_Aviv: IL
Asia/Ashkhabad: TM
Asia/Calcutta: IN
Asia/Chungking: CN
Asia/Dacca: BD
Asia/Istanbul: TR
Asia/Katmandu: NP
Asia/Macao: MO
Asia/Rangoon: MM
Asia/Saigon: VN
Asia/Thimbu: BT
Asia/Ujung_Pandang: ID
Asia/Ulan_Bator: MN

Atlantic/Jan_Mayen: SJ
Atlantic/Faeroe: FO

Australia/ACT: AU
Australia/LHI: AU
Australia/NSW: AU
Australia/Canberra: AU
Australia/Currie: AU
Australia/North: AU
Australia/Queensland: AU
Australia/South: AU
Australia/Tasmania: AU
Australia/Victoria: AU
Australia/West: AU
Australia/Yancowinna: AU

Europe/Belfast: GB
Europe/Tiraspol: MD
Europe/Uzhgorod: UA
Europe/Zaporozhye: UA
Europe/Kiev: UA
Europe/Nicosia: CY

Pacific/Samoa: AS
Pacific/Enderbury: KI
Pacific/Johnston: US
Pacific/Yap: FM
Pacific/Ponape: FM
Pacific/Truk: FM

Brazil/Acre: BR
Brazil/DeNoronha: BR
Brazil/East: BR
Brazil/West: BR

Canada/Atlantic: CA
Canada/Central: CA
Canada/Eastern: CA
Canada/Mountain: CA
Canada/Newfoundland: CA
Canada/Pacific: CA
Canada/Saskatchewan: CA
Canada/Yukon: CA

Chile/Continental: CL
Chile/EasterIsland: CL

Mexico/BajaNorte: MX
Mexico/BajaSur: MX
Mexico/General: MX

US/Alaska: US
US/Aleutian: US
US/Arizona: US
US/Central: US
US/East-Indiana: US
US/Eastern: US
US/Hawaii: US
US/Indiana-Starke: US
US/Michigan: US
US/Mountain: US
US/Pacific: US
US/Samoa: AS

CET: BE
EET: GR
MET: BE
WET: PT

CST6CDT: US
EST5EDT: US
EST: PA
HST: US
MST7MDT: US
MST: US
PST8PDT: US

Cuba: CU
Egypt: EG
Eire: IE
GB: GB
GB-Eire: GB
Hongkong: HK
Iceland: IS
Iran: IR
Israel: IL
Jamaica: JM
Japan: JP
Kwajalein: MH
Libya: LY
NZ: NZ
NZ-CHAT: NZ
Navajo: US
PRC: CN
Poland: PL
Portugal: PT
ROC: TW
ROK: KR
Singapore: SG
Turkey: TR
W-SU: RU
Loading

0 comments on commit b189cde

Please sign in to comment.