spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.99k stars 183 forks source link

st.add(1, 'date') doesn't get over day barrier on DST change #193

Closed jecraig closed 4 years ago

jecraig commented 4 years ago

Using version 6.4.1. Here's the output from the console.

tzCheckDate.epoch
1572681600000

tzCheckDate.timezone().name
"America/Los_Angeles"

tzCheckDate.format('iso')
"2019-11-02T00:00:00.000-08:00"

tzCheckDate.add(1, 'date').format('iso')
"2019-11-02T23:00:00.000-08:00"

As you can see, the date doesn't make it over to 2019-11-03. Because of this, using startOf date just puts you back where you were before the add.

tzCheckDate.add(1, 'date').format('iso')
"2019-11-02T23:00:00.000-08:00"

tzCheckDate.add(1, 'date').startOf('date').format('iso')
"2019-11-02T00:00:00.000-08:00"

Found this because we got an infinite loop trying to iterate over all of the dates between two dates.

jecraig commented 4 years ago

Shifting all of my dates to .hour(12) appears to be a decent workaround. It appears to really only happen when your date starts in the DST zone.

spencermountain commented 4 years ago

hey Jacob, good find. I'm worried this may be another view of #182 . My guess is that it gets close to the dst-change, but then finds itself off by an hour.

yes- particularly hitting the infinite loop. This needs to be fixed. in post-processing, the library should realize it hasn't shifted a whole day yet, and make a correction. I'm surprised this was not caught. Will add to the next release. cheers

spencermountain commented 4 years ago

hey Jacob, this should be fixed now in 6.6.0 thanks for your patience let me know if you see anything else