question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird bug locale dates 1900 and before

See original GitHub issue

Am I missing something? Dates are wrong for 1900 and before:

https://codesandbox.io/s/ww5859zjwk

Very important: this is happening when I set my windows timezone to UTC +01 Madrid. If I set it to UTC +00 London the same bug occurs for 1922 and before. This is only happening in Chrome.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
icambroncommented, Feb 11, 2019

This is the weirdest bug yet! I figured it out and unfortunately I don’t have a solution. Here’s the problem: In Madrid, in 1900, the offset from UTC was 14 minutes and 44 seconds. It’s crazy but true. You can go here and pull down the dropdown to 1900 and see it.

Unfortunately, the JS Date methods will only give TZ offsets in minutes:

new Date(1900, 0, 1).getTimezoneOffset() //=> 14

which is of course wrong by 44 seconds. Luxon has some complicated logic built for handling a host of browser DST bugs and for implementing non-local time zones. That logic depends on getTimeZoneOffset. The result is that Luxon is off by 44 seconds on the time, resulting in:

DateTime.local(1900, 1, 1).toJSDate().toString()
'Sun Dec 31 1899 23:59:16 GMT-0014 (Central European Standard Time)'

The bug only happens in Chrome because it’s the only browser with good enough historical data to have this problem. I’m not sure what to do here:

  • There may be a way to get a more precise offset by parsing some string, but given that Luxon does this computation on most operations, that’s probably too painful performance-wise, not to mention brittle. (Edit: I haven’t found such a way anyway)
  • Ideally, browsers should provide something like getTimezoneOffsetMilliseconds() but they don’t
  • There might be a way to avoid doing this complicated logic on local dates, but that has many other downsides, and anyway, the same problem would show up with your computer set to somewhere else but your code using “Europe/Madrid” explicitly.

So barring a time machine to go back and change Spain’s historic offsets, I’m not sure how to fix this.

I wasn’t able to reproduce any issues with London.

0reactions
icambroncommented, May 5, 2019

I’m going to close this. While I agree this is a bug, it’s not one that Luxon can fix, so it’s just taking up space in the issue list.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Excel Dates That Won't Change Format - Contextures
How to fix Excel dates that will not change format. Fix dates that end up in the wrong order when sorted. Use built-in...
Read more >
Year 1900 problem - Wikipedia
The year 1900 problem concerns the misinterpretation of years recorded by only their last two digits, and whether they occurred before or after...
Read more >
Demystifying DateTime Manipulation in JavaScript - Toptal
Time and date manipulation is notoriously difficult. Developers encountering time zone rules, leap seconds, differences in locale-specific formatting are ...
Read more >
Why is subtracting these two times (in 1927) giving a strange ...
The real answer is to always, always use seconds since an epoch for logging, like the Unix epoch, with 64 bit integer representation...
Read more >
6 Ways to Fix Dates Formatted as Text in Excel
You can quickly fix all dates using the error checking by selecting all of your cells containing date text strings before clicking on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found