Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weekOfYear and yearOfWeek for Gregorian calendar needs clarifying #3096

Open
o-t-w opened this issue Feb 25, 2025 · 8 comments
Open

weekOfYear and yearOfWeek for Gregorian calendar needs clarifying #3096

o-t-w opened this issue Feb 25, 2025 · 8 comments

Comments

@o-t-w
Copy link

o-t-w commented Feb 25, 2025

There is a lack of clarity and differences of opinion about whether the Gregorian calendar should use the ISO-8601 week numbering system.

See this Firefox bug and this bug in the Temporal polyfill repo.

@justingrant
Copy link
Collaborator

I think that @sffc has some info on the week-numbering question.

@fabon-f
Copy link
Contributor

fabon-f commented Feb 26, 2025

I think the definition of 'first week of year' is locale-dependent (getWeekInfo method in Intl Locale Info API provides information about it) even for gregorian calendar, but Temporal.PlainDate and other types doesn't contain locale info. Therefore, it's not obvious what weekOfYear and yearOfWeek should be in 'gregory' calendar (and maybe other calendars except iso8601). Perhaps returning undefined can be an option. (ref: #2744)

@sffc
Copy link
Collaborator

sffc commented Feb 26, 2025

See tc39/proposal-intl-locale-info#86 (comment)

CLDR decided to recommend consistently using ISO-8601 week numbering across all regions, primarily due to lack of evidence of user expectations contrary to that behavior. The only evidence we have of user expectations is that users who expect ISO-8601 week numbers are surprised when they switch to a different region and get different week numbers.

@arshaw
Copy link
Contributor

arshaw commented Feb 28, 2025

Thanks for the clarity @sffc. To answer @anba's question here, will this be included as part of the spec?

@sffc
Copy link
Collaborator

sffc commented Feb 28, 2025

Hmm, I feel like the behavior across calendars should be in scope of https://github.com/tc39/proposal-intl-era-monthcode. I fully expect that ISO and Gregorian will use the same numbering, but I can't guarantee what happens in other calendar systems. I think I recall us saying before that calendars are allowed to return undefined if week numbers are not conventionally used.

I think the scope of 262 would just to be that the numbers don't change across regions within the same calendar, which is effectively what we have since these functions don't take a locale.

@arshaw
Copy link
Contributor

arshaw commented Feb 28, 2025

Thanks @sffc. Understood that week numbers wouldn't change across regions.

When you say you "fully expect that ISO and Gregorian will use the same numbering", would the spec have an opinion about that? What should Firefox do?

Right now, the reference implementation does NOT produce the same values for iso8601 and gregory because:

// both iso8601 and gregory expect first day-of-week to be 1 (Monday)
const fdow = id === 'iso8601' ? 1 : calendar.helper.getFirstDayOfWeek();

// iso8601 expects first week to contain 4-or-more days, whereas gregory requires only 1
const mdow = id === 'iso8601' ? 4 : calendar.helper.getMinimalDaysInFirstWeek();

https://github.com/tc39/proposal-temporal/blob/726becd0b962ab48604500311f0bc2518594275e/polyfill/lib/calendar.mjs#L93C55-L93C80

@arshaw
Copy link
Contributor

arshaw commented Feb 28, 2025

@sffc, actually no need for a response just yet, let me dig more into the discrepancy between the reference implementation and Firefox...

@sffc
Copy link
Collaborator

sffc commented Feb 28, 2025

When you say you "fully expect that ISO and Gregorian will use the same numbering", would the spec have an opinion about that? What should Firefox do?

I think 262 shouldn't have an opinion but 402 could have one, in the context of https://github.com/tc39/proposal-intl-era-monthcode

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

No branches or pull requests

5 participants