Closed Bug 1950162 Opened 6 months ago Closed 3 months ago

Temporal API, wrong results for yearOfWeek/weekOfYear w/ calendar:gregory

Categories

(Core :: JavaScript: Standard Library, defect, P3)

Firefox 137
defect

Tracking

()

RESOLVED FIXED
141 Branch
Tracking Status
firefox141 --- fixed

People

(Reporter: arshaw, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Steps to reproduce:

Test on Firefox nightly 137.0a1 (2025-02-24) (aarch64)

const lastDay2029 = Temporal.PlainDate.from('2029-12-31[u-ca=gregory]');

/*
EXPECT: 1
ACTUAL: 53
*/
console.log(lastDay2029.weekOfYear)

/*
EXPECT: 2030
ACTUAL: 2029
*/
console.log(lastDay2029.yearOfWeek)

Actual results:

See above

Expected results:

See above

The Bugbug bot thinks this bug should belong to the 'Core::JavaScript: Standard Library' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → JavaScript: Standard Library
Product: Firefox → Core

Can you file an issue at https://github.com/tc39/proposal-temporal/ to clarify the spec? If it is expected that the Gregorian calendar uses exactly the same week numbering system as the ISO-8601 calendar, the spec should require this behaviour. Thanks!

Blocks: temporal
Severity: -- → S3
Priority: -- → P3

Hi André, hope you are well. After digging further, I've realized the problem isn't that gregorian week numbers should/shouldn't be following iso8601, but rather the gregorian week numbers that Firefox is generating are buggy on their own right. Please see this recreation code:

d = Temporal.PlainDate.from('<insert PlainDate string>');
console.log(d.yearOfWeek + ', ' + d.weekOfYear);

Results:

PlainDate string Day of Week Ref Impl Firefox
2029-12-30[u-ca=gregory] 7 - Sun 2029, 52 2029, 52
2029-12-31[u-ca=gregory] 1 - Mon 2030, 1 2029, 53
2030-01-01[u-ca=gregory] 2 - Tue 2030, 1 2030, 1
2030-01-02[u-ca=gregory] 3 - Wed 2030, 1 2030, 1
2030-01-03[u-ca=gregory] 4 - Thu 2030, 1 2030, 1
2030-01-04[u-ca=gregory] 5 - Fri 2030, 1 2030, 1
2030-01-05[u-ca=gregory] 6 - Sat 2030, 1 2030, 1
2030-01-06[u-ca=gregory] 7 - Sun 2030, 1 2030, 1
2030-01-07[u-ca=gregory] 1 - Mon 2030, 2 2030, 2

Note that Firefox is amazingly determining that week 2030, 1 only has 6 days in it!

I tried tracing the code from here -> here, and I see this is offloaded to ICU4X. All the configuration looks correct to me (firstWeekday = Monday, minWeekDays = 1), so could it be that this is a bug in ICU4X?

Err, maybe ICU4X isn't necessarily "buggy" but it's opinionated about week numbers spanning as far as possible until year-end.

This was discussed in the 3/6/2025 Temporal champions meeting. It's likely a bug in ICU4X not conforming to the latest CLDR. I've opened a ticket here: https://github.com/unicode-org/icu4x/issues/6247

Assignee: nobody → andrebargull
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Pushed by andre.bargull@gmail.com: https://github.com/mozilla-firefox/firefox/commit/efd59ac77d7b https://hg.mozilla.org/integration/autoland/rev/572d1620d5bd Return undefined for weekOfYear and yearOfWeek for Gregorian. r=spidermonkey-reviewers,dminor
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 141 Branch
QA Whiteboard: [qa-triage-done-c142/b141]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: