spencermountain / spacetime

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

Timezone conversion issue, (goes wrong direction) #284

Closed jisaacks closed 2 years ago

jisaacks commented 3 years ago

Here is an example:

const z = 'America/New_York'
const a = spacetime('03/14/2021, 1:59 AM', z) // The last minute of the timezone
const b = spacetime('03/14/2021, 2:00 AM', z)

// This is correct.
a.format('iso')
// got: "2021-03-14T01:59:00.000-05:00"

// This is also correct
a.add(1, 'minute').format('iso')
// got: "2021-03-14T03:00:00.000-04:00"

// this is wrong
b.format('iso')
// got: "2021-03-14T01:00:00.000-05:00"
// expecting "2021-03-14T03:00:00.000-04:00"

The hour is subtracted (goes from 2 to 1 during the time change) but it should be added (go from 2 to 3)

spencermountain commented 3 years ago

hey @jisaacks thanks for the issue. My gut says it's another example of #235 - this is a tricky case where using native js Date objects for the calculation - it's a chicken and the egg issue. I'll check it out today, to confirm I've got a fix for this, and hope to release it sometime in may, but no promises. cheers

jisaacks commented 3 years ago

Great thanks, I am subscribed to that one too.

Also thanks so much for this library I been wanting something like this for years.

I actually built my own (eerily similar) but it relied on Intl, don't understand how you did it without it!

spencermountain commented 3 years ago

haha, thanks. I have woken up in the night thinking 'wait, how-the...' Like, there may be a conceptual reason why this should not work, and I just haven't realized it yet. Been hoping the temporal folks just solve-everything and we can just go to the beach.

ok, since you seem like the worlds-best githubber, let me try to bait you to help -

Here is an early attempt to formalize the '2nd sunday of march' folk-patterns.

I've looked pretty hard, and I don't believe anybody has formalized this before. It's crazy. This website kinda goes through them. If we could write a function guessDstDate(iana, year) that returned an epoch, it would fix 235, and avoid having to republish new dst dates every year.

Let me know! cheers

spencermountain commented 2 years ago

merging with #235 ->