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.

Converting dates (from JS) gets incorrect results if crossing DST boundary

See original GitHub issue

(Actually also with different timezones, but you state in the README you make a choice of not handling timezones at all, so let’s focus on the DST issue.)

This is a little difficult to explain though. Let’s say we ended Daylight Saving Time last Sunday. Let d1 be a date today, and d2 be a date exactly a week ago.

To test more easily, let’s say we set dateNF: 'yyyy-mm-dd"T"hh:MM:ss'. Then put d1 and d2 in two columns in the same row and export a csv. (The bug is not actually related to csv, it’s just easier to test if we convert to string.)

Expected: the time part (after T) is identical for both.

Actual: the time part for d2 will be off by one hour (e.g. 10:28 instead of 11:28).

The reason for this is the dnthresh constant is calculated based on the timezone offset of the current time as of when the library is loaded. So dates with any other offset (including same timezone but different DST status) will break the calculation.

PR coming up in a few minutes.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
cemremengucommented, Nov 15, 2018

Spent hours trying to figure out why our tests were failing 😄

Any ETA for the patch release?

2reactions
SheetJSDevcommented, Oct 30, 2018

Thanks for looking into this @lalomartins !

The overarching problem is that Excel doesn’t actually have a proper concept of time. It’s shoehorned into the numeric model in a very simplistic way, where each calendar day has 86400 equally-spaced seconds and midnight is pinned to 0. This very clearly creates problems around DST.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Daylight saving time and time zone best practices [closed]
When storing a timezone, you need the name, timestamp and the offset. This is required because governments sometimes change the meanings of their...
Read more >
Incorrect date value from standard time to DST - Microsoft Learn
Symptoms. When you use the JavaScript Date object to compute dates under certain circumstances, users may see results that are apparently ...
Read more >
Migrating datetime to datetimeoffset | Josh the Coder
We have lots of historical data that crosses the DST boundary each ... way to get our inputdate “without offset information” is to...
Read more >
timechange: Efficient Manipulation of Date-Times
a list, all contained elements are updated the new list is returned. tz a character string containing the time zone to convert to....
Read more >
Demystifying DateTime Manipulation in JavaScript - Toptal
If you instead want to get the current time stamp, you can create a new Date ... Converting a string to a JavaScript...
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