Skip to content

Backport #4163 to 4.x: Intl.Locale getWeekInfo picks its region through RegionPreference - #4168

Merged
lahma merged 1 commit into
sebastienros:4.xfrom
lahma:backport/4163-weekinfo-region-preference
Sep 24, 2026
Merged

lahma merged 1 commit into
sebastienros:4.xfrom
lahma:backport/4163-weekinfo-region-preference

Conversation

@lahma

@lahma lahma commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Backports #4163 (commit ad440908afe557a2bab81c9420d60753b83d62d3) to 4.x.

Base: 4.x at 6b39fa0760d700ce13180ed9ee0a250b082d19c3.

What it fixes

Intl.Locale.prototype.getWeekInfo read CLDR's week data for the tag's region subtag and nothing else. A tag without a region subtag therefore got the world's week (001), and the -u-rg- and -u-sd- keywords were ignored.

It now picks the region the way RegionPreference and WeekInfoOfLocale do, in this order:

  1. a -u-rg- override, if CLDR has week data for it
  2. the region subtag
  3. a -u-sd- subdivision's region
  4. the region Add Likely Subtags supplies
  5. 001

Both firstDay and weekend are read for that region. A -u-fw- keyword still wins for firstDay.

What changes for a script. Both new answers are what the specification and every browser give:

new Intl.Locale('en').getWeekInfo().firstDay;                // was 1, now 7: "en" is likely "en-US"
new Intl.Locale('en-US-u-rg-gbzzzz').getWeekInfo().firstDay; // was 7, now 1: the override names Great Britain

What the pick carried and what it did not

file on 4.x
Jint/Native/Intl/RegionPreference.cs applied verbatim; stays internal
Jint/Native/Intl/Data/WeekData.cs applied verbatim (GetLookupRegion, internal)
Jint/Native/Intl/IntlUtilities.cs applied verbatim: CanonicalizeUnicodeLocaleId goes private → internal, on an internal class
Jint/Native/Intl/LocalePrototype.cs hand-ported, see the provider rung
Jint/Native/Intl/DefaultCldrProvider.cs dropped, see the provider rung
Jint.Tests/Runtime/IntlLocaleRegionPreferenceTests.cs transcribed NUnit → xUnit v3 ([TestCase] → [Theory] + [InlineData], [Test] → [Fact]). Main's two provider tests are dropped (below)
Jint.Tests.Test262/Test262Harness.settings.json the same four getWeekInfo exclusions are removed. 4.x carried them too, and all four files exist in 4.x's pin 3655e746
Jint.Tests/SpecAnchors.txt, docs/guide/migrating-to-v5.md dropped; neither file exists on 4.x

The provider rung

On main, getWeekInfo asks the configured ICldrProvider.GetWeekInfo first, and only falls back to the embedded CLDR data when the provider returns null. Main added that in #3357, a v5 change that also removed public members, so it is not on this branch. 4.x's getWeekInfo never asks the provider. It reads the embedded WeekData for locale.Region. The port changes only that lookup, to WeekData.GetLookupRegion(RegionPreference.Of(locale.Locale)). It adds no provider rung.

Main's hunk to DefaultCldrProvider.GetWeekInfo is left out. Nothing in the 4.x engine calls that method, so only a host calling it directly through ICldrProvider can see it. Main changed it because on main that method answers the script. Here it does not. It also already disagrees with the script in another way: it returns a hardcoded Saturday–Sunday weekend for every region, which main fixed in #3357. Fixing only its region would change a public method's answer with nothing in script depending on it, and would leave it half-corrected: "fa" would get Iran's Saturday first day with a Saturday–Sunday weekend. For the same reason, main's two tests that need a provider are not ported. One subclasses DefaultCldrProvider, which is sealed on 4.x, to test the provider rung. The other tests the dropped hunk.

The likely-subtags data

The Add Likely Subtags step reads Data/LikelySubtags.cs / LikelySubtagsData.cs / LikelySubtags.txt. The week lookup reads Data/WeekData.Data.cs / WeekData.txt. The keyword regions are canonicalized through LocaleData. All of these are byte-identical between 4.x and main (git diff upstream/4.x upstream/main -- Jint/Native/Intl/Data/ touches none of them), so no data table comes with this port.

Verification

The ported tests (26 cases) ran first against unfixed 4.x (test file only), then against the fixed tree:

net10.0 net472
before the fix 13 failed / 13 passed of 26 13 failed / 13 passed of 26 (the same 13)
after the fix 0 failed / 26 passed 0 failed / 26 passed

The four test262 files, each in strict and sloppy mode (8 cases), with the exclusions removed:

  • Unfixed (the LocalePrototype lookup reverted to locale.Region): all 8 fail. For example, getWeekInfo() for "en-US-u-rg-dezzzz" should return firstDay that matches the override region Expected SameValue(«7», «1»), and getWeekInfo() for "th" should return firstDay that matches the likely region Expected SameValue(«1», «7»).
  • Fixed: all 8 pass, and so do the other 14 getWeekInfo cases (22/22).

Full solution, one dotnet test -c Release run:

project net10.0 net472
Jint.Tests 7639 passed / 0 failed / 4 skipped 7554 passed / 0 failed / 4 skipped
Jint.Tests.PublicInterface (incl. the public-API snapshot) 1874 passed / 0 failed / 9 skipped 1866 passed / 0 failed / 9 skipped
Jint.Tests.CommonScripts 28 passed / 0 failed 28 passed / 0 failed
Jint.Tests.SourceGenerators 52 passed / 0 failed n/a
Jint.Tests.Test262 (pin 3655e746) 102,507 passed / 2 failed / 175 skipped (see below) n/a

The public-API snapshots pass untouched, and no .received file was written. Everything this change touches is internal or private.

test262. Both failures were staging/sm/Array/toSpliced-dense.js, strict and sloppy. Each hit the 30 s timeout under load; this is one of the known load flakes. Re-run alone with --filter "Name~toSpliced-dense.js", both pass in 1 s. The net result is 102,509 passed / 0 failed / 175 skipped. That is the 4.x control's 102,501 / 0 / 183, plus the 8 cases (4 files × strict and sloppy) that the removed exclusions had been skipping.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PanPJbBD7pQC9fRiTpHxvs

…region through RegionPreference

Backport of PR sebastienros#4163 (commit ad44090) from main.

getWeekInfo read CLDR week data for the tag's literal region subtag only, so a tag
without one fell to 001 and the -u-rg- and -u-sd- keywords were ignored: "en"
answered Monday and "en-US-u-rg-gbzzzz" Sunday. It now picks the region the way
ECMA-402 RegionPreference does: a -u-rg- override CLDR has week data for, then the
region subtag, then a -u-sd- subdivision's region, then the region Add Likely Subtags
supplies, then 001. Both firstDay and weekend are read for that region; a -u-fw-
keyword still wins for firstDay.

Observable change, both now what the specification and every browser answer:
- new Intl.Locale('en').getWeekInfo().firstDay goes 1 -> 7 ("en" is likely "en-US").
- new Intl.Locale('en-US-u-rg-gbzzzz').getWeekInfo().firstDay goes 7 -> 1 (the
  override names Great Britain).

Adapted for 4.x:
- Jint/Native/Intl/RegionPreference.cs, Data/WeekData.cs, IntlUtilities.cs: applied
  verbatim. RegionPreference stays internal; CanonicalizeUnicodeLocaleId goes private ->
  internal on an internal class. The likely-subtags step reads LikelySubtags /
  LikelySubtagsData, and the week step WeekData.Data.cs; all of those (and their .txt
  sources) are byte-identical between 4.x and main, so no data table is ported.
- Jint/Native/Intl/LocalePrototype.cs: hand-ported. 4.x's getWeekInfo never asks the
  configured ICldrProvider (main's provider rung came with sebastienros#3357, a v5 API change not on
  this branch); it reads the embedded WeekData for locale.Region. That lookup now reads
  WeekData.GetLookupRegion(RegionPreference.Of(locale.Locale)) instead. No provider rung
  is added.
- Jint/Native/Intl/DefaultCldrProvider.cs: main's hunk dropped. On 4.x nothing in the
  engine calls GetWeekInfo, so the method answers only a host that calls it directly. On
  main the hunk exists because that method answers the script; here it does not, and
  4.x's version already disagrees with the script in other ways (a hardcoded Saturday-
  Sunday weekend, which main fixed in sebastienros#3357). Changing only its region would move a
  public method's answer with no script-visible effect and leave it half-corrected
  ("fa" would get Iran's Saturday with a Saturday-Sunday weekend).
- Jint.Tests/Runtime/IntlLocaleRegionPreferenceTests.cs: transcribed NUnit -> xUnit v3
  ([TestCase] -> [Theory] + [InlineData], [Test] -> [Fact]). Main's two provider tests
  are dropped: one subclasses DefaultCldrProvider, which is sealed on 4.x, to test the
  provider rung 4.x does not have; the other tests the DefaultCldrProvider hunk not
  ported here.
- Jint.Tests.Test262/Test262Harness.settings.json: the same four getWeekInfo exclusions
  4.x carried are removed; all four files exist in 4.x's pin (3655e746).
- Jint.Tests/SpecAnchors.txt, docs/guide/migrating-to-v5.md: dropped; neither exists on
  4.x.

Evidence:
- IntlLocaleRegionPreferenceTests on unfixed 4.x: net10.0 13 failed, 13 passed of 26;
  net472 13 failed, 13 passed of 26 (the same 13 cases on both).
- With the fix: net10.0 26/26 passed; net472 26/26 passed.
- test262 intl402/Locale/prototype/getWeekInfo/{likely-subtags-region,region-override,
  region-priority,subdivision-region}.js with the exclusions removed: unfixed, all 8
  cases (strict and sloppy) fail, e.g. 'getWeekInfo() for "en-US-u-rg-dezzzz" should
  return firstDay that matches the override region Expected SameValue(«7», «1»)';
  fixed, all 8 pass (22/22 getWeekInfo cases).
- Full solution, one dotnet test -c Release run:
  Jint.Tests 7639 passed / 4 skipped (net10.0) and 7554 / 4 (net472);
  Jint.Tests.PublicInterface 1874 / 9 (net10.0) and 1866 / 9 (net472), public-API
  Verify snapshots unchanged; Jint.Tests.CommonScripts 28 / 0 on both;
  Jint.Tests.SourceGenerators 52 / 0. No failures in any of them.
- test262 (4.x pin 3655e746), from that same run: 102,507 passed, 2 failed, 175
  skipped. The two were staging/sm/Array/toSpliced-dense.js, strict and sloppy, both
  30 s timeouts under load (the known flake); re-run alone, both pass in 1 s. Net:
  102,509 / 0 / 175 - the 4.x control's 102,501 / 0 / 183 plus the 8 cases (4 files x
  strict and sloppy) the removed exclusions had been skipping.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PanPJbBD7pQC9fRiTpHxvs
@lahma
lahma merged commit 2597a68 into sebastienros:4.x Sep 24, 2026
5 checks passed
@lahma
lahma deleted the backport/4163-weekinfo-region-preference branch September 25, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant