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

Unexpected results near DST 2023 boundaries (Europe/Helsinki) #374

Closed
pulakkam opened this issue Feb 17, 2023 · 4 comments
Closed

Unexpected results near DST 2023 boundaries (Europe/Helsinki) #374

pulakkam opened this issue Feb 17, 2023 · 4 comments

Comments

@pulakkam
Copy link

Hello,

I checked if there are any problems related to DST 2023 in Europe/Helsinki and there seem to be some.

My test code:

import spacetime from 'spacetime'

const isotimes = [
  '2023-03-26T00:30:00.000Z', // March 2023
  '2023-03-26T01:30:00.000Z',
  '2023-03-26T02:30:00.000Z',
  '2023-03-26T03:30:00.000Z',
  '2023-03-26T04:30:00.000Z',
  '2023-03-26T05:30:00.000Z',
  '2023-10-29T00:30:00.000Z', // October 2023
  '2023-10-29T01:30:00.000Z',
  '2023-10-29T02:30:00.000Z',
  '2023-10-29T03:30:00.000Z',
  '2023-10-29T04:30:00.000Z',
]

isotimes.forEach((isotime) => {
  const time = spacetime(isotime)
  console.log(isotime)
  console.log(time.format('iso'))
  console.log(time.goto('Europe/Helsinki').format('iso'))
  console.log()
})

Results:

2023-03-26T00:30:00.000Z
2023-03-26T00:30:00.000Z
2023-03-26T02:30:00.000+02:00

2023-03-26T01:30:00.000Z
2023-03-26T01:30:00.000Z
2023-03-26T05:30:00.000+03:00 // Expected: 2023-03-26T04:30:00.000+03:00

2023-03-26T02:30:00.000Z
2023-03-26T02:30:00.000Z
2023-03-26T06:30:00.000+03:00 // Expected: 2023-03-26T05:30:00.000+03:00

2023-03-26T03:30:00.000Z
2023-03-26T02:30:00.000Z      // Expected: 2023-03-26T03:30:00.000Z
2023-03-26T06:30:00.000+03:00

2023-03-26T04:30:00.000Z
2023-03-26T04:30:00.000Z
2023-03-26T07:30:00.000+03:00

2023-03-26T05:30:00.000Z
2023-03-26T05:30:00.000Z
2023-03-26T08:30:00.000+03:00

2023-10-29T00:30:00.000Z
2023-10-29T00:30:00.000Z
2023-10-29T03:30:00.000+03:00

2023-10-29T01:30:00.000Z
2023-10-29T00:30:00.000Z      // Expected: 2023-10-29T01:30:00.000Z
2023-10-29T03:30:00.000+03:00

2023-10-29T02:30:00.000Z
2023-10-29T02:30:00.000Z
2023-10-29T03:30:00.000+02:00 // Expected: 2023-10-29T04:30:00.000+02:00

2023-10-29T03:30:00.000Z
2023-10-29T03:30:00.000Z
2023-10-29T05:30:00.000+02:00

2023-10-29T04:30:00.000Z
2023-10-29T04:30:00.000Z
2023-10-29T06:30:00.000+02:00

Is there something I could do to get expected results?

Thank you.

@spencermountain
Copy link
Owner

hey Matti - thank you for the good bug. I think i know what is happening, and it is crazy.

There's some ambiguity when parsing a iso timezone. We get '+05:30' and we try to match it to the most appropriate iana code. We let users clear this up with spacetime(iso, tz).
There are cases when those two timezones don't line up - and we flail around trying to guess timezones.

I think that's what's happening here.

can you confirm that this produces the correct results?

isotimes.forEach((isotime) => {
  const time = spacetime(isotime, 'ETC/UTC')
  console.log(isotime)
  console.log(time.format('iso'))
  console.log(time.goto('Europe/Helsinki').format('iso'))
  console.log()
})

This is pretty dirty. I'll need to think about what the best way to address this is.
let me know if that clears it up
cheers

@pulakkam
Copy link
Author

Actually the results are identical, no difference between my original code and your version.

@spencermountain
Copy link
Owner

oof, sorry! lemme check it out after a good sleep.

@spencermountain
Copy link
Owner

oh - yup, this is a dupe of #235
sorry for my code-blindness yeterday
i'm working on a fix. it requires a re-write. Hope to have it ready in a couple weeks, atleast as a beta
thanks for your patience. the offsets will only be off by an hour, within an hour of a dst change
cheers

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