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

Local Week year is wrong on Firefox for en-US, fr-CA (locales with weeks starting on Sunday). #1563

Open
JeanMeche opened this issue Jan 8, 2024 · 9 comments

Comments

@JeanMeche
Copy link

I'm opening this bug for tracking purposes,

Currently the week year format (iiii) can be wrong on firefox because it doesn't support getWeekInfo and Luxon uses the following fallback (which is the ISO definition I believe):

luxon/src/impl/locale.js

Lines 320 to 324 in 3125686

const fallbackWeekSettings = {
firstDay: 1,
minimalDays: 4,
weekend: [6, 7],
};

@ChrisMBarr
Copy link

ChrisMBarr commented Oct 15, 2024

Yep, Running this:

DateTime.now().endOf('week', { useLocaleWeeks: true }).toFormat('EEEE');

returns "Saturday" in Chrome, and "Sunday" in Firefox.

It looks like the fix for this is to set this:

Settings.defaultWeekSettings = { firstDay: 7, minimalDays: 1, weekend: [6, 7] }

@diesieben07
Copy link
Collaborator

diesieben07 commented Oct 15, 2024

Relevant Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1693576

An alternative is to use a polyfill: https://formatjs.io/docs/polyfills/intl-locale

@ChrisMBarr
Copy link

I get that it would be ideal to have the browser inform the library of what it believes the locale info is, but honestly it seems kind of strange to have to do all of this configuration just so I can have consistent behavior across browsers

@diesieben07
Copy link
Collaborator

@ChrisMBarr This is unfortunately the world we live in. Luxon's place is to provide a nicer API abstracted away from the various Intl APIs. Luxon was specifically born to not have to ship locale and time zone data like this and instead rely on the Intl APIs. It's the job of the library user to ensure their platform support the needed features or fill them in with a polyfill.
When I added the support for locale weeks to Luxon I had secretly hoped that Firefox would soon follow with their implementation, but it seems this is not to be. Any suggestions how to better handle this situation are welcome.

The documentation here could definitely be improved though, especially with relevant links for how to work around various shortcomings.

@ChrisMBarr
Copy link

I don't know anything about how the internals of Luxon work. but perhaps there could be some sort of polyfill that is recommended to use if you need Firefox support. Something that would wither mimic Intl or maybe just provide a mapping of locales to week info defaults.

Or at the very least a big banner on the docs that says "Hey, all week information will be incorrect in Firefox unless you do this"

Just something to make it usable so you can trust Luxon. I love the API but now I find myself second guessing everything, checking it in all browsers, and writing extra unit tests... and now I might have to find a way to run my unit tests in multiple browsers.

@diesieben07
Copy link
Collaborator

I recommended a polyfill above that you can use.
And like I said, we should definitely improve the docs regarding browser support. Help is very welcome.

@ChrisMBarr
Copy link

II just added a Firefox test runner to my project, and I'm glad I did. Lots of date related failures. I'd like to use that polyfill... but when I click the link I see this which makes me hesitant
image

@diesieben07
Copy link
Collaborator

diesieben07 commented Oct 16, 2024

When I linked to it the other day it still worked, I am guessing their certificate just expired.
You can find the Github repo here: https://github.com/formatjs/formatjs

I am surprised you are seeing many failures - are they all related to the missing locale week support?

@ChrisMBarr
Copy link

When I say "failures" i just mean that I have some date parsing/transformation stuff that is just outputting stuff I'm not expecting. Part of it turned out to be a testing issue where those Settings that I set in my app just aren't being loaded in my unit test - that actually fixed most of the issues. Some others just had to do with how firefox parsed a new Date() from a string, apparently Chrome is more lenient on the allowed formatting!

All good now thankfully!

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

3 participants