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

Incorrect functionality of DateTime.fromJSDate in Chrome browser for years older than 1935 #1646

Open
alimemz opened this issue Jul 20, 2024 · 1 comment

Comments

@alimemz
Copy link

alimemz commented Jul 20, 2024

Describe the bug
For years 1935 and before, luxon's DateTime.fromJSDate acts incorrectly on Chrome browser while it works correctly on Firefox.

To Reproduce
DateTime.fromJSDate(new Date('1935-01-01 00:00:00')).toFormat('yyyy-MM-dd HH:mm:ss');
// On Chrome it wrongly return 1934-12-31 23:59:16
// On Firefox it correctly return 1935-01-01 00:00:00

Important note is that the following return the same milliseconds on both browsers:
DateTime.fromJSDate(new Date('1935-01-01 00:00:00')).valueOf();
// On both Chrome and Firefox return -1104549944000

More examples in the attached screenshots:
luxon issue Chrome
luxon firefox

Actual vs Expected behavior
DateTime.fromJSDate should work correctly and consistently across browsers for historical dates, so that on Chrome it parses the passed JS Date with the expected precision and doesn't jump back.

Desktop (please complete the following information):

  • OS: Ubuntu 22.04.4 LTS
  • Browser Chrome 126.0.6478.61, Firefox 128
  • Luxon version: 3.4.4
  • Your timezone: Asia/Tehran

Additional context

@diesieben07
Copy link
Collaborator

Unfortunately this is just down to a problem with fractional timezone offsets and how browsers handle them differently.
The following behaves differently in Chrome and Firefox (assuming timezone Asia/Tehran):

console.log(new Date('1935-01-01 00:00:00').getTimezoneOffset());

In Chrome this returns -205, in Firefox it returns -205.73333333333. I am not sure if there is something that can be done to work around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants