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

Daylight savings conversion error #660

Closed
brianmay opened this issue Apr 5, 2021 · 4 comments
Closed

Daylight savings conversion error #660

brianmay opened this issue Apr 5, 2021 · 4 comments

Comments

@brianmay
Copy link

brianmay commented Apr 5, 2021

Steps to reproduce

iex(14)> Timex.Timezone.convert(~U[2021-04-03 15:30:00Z], "Australia/Melbourne")
#DateTime<2021-04-04 01:30:00+10:00 AEST Australia/Melbourne>

Description of issue

This is wrong, it shows the non-daylight savings time.

But daylight savings doesn't end here until 3am local time. Or 16:00 UTC time. Clearly 15:30Z is before 16:00Z. So I would expect that the output should be:

iex(14)> Timex.Timezone.convert(~U[2021-04-03 15:30:00Z], "Australia/Melbourne")
#DateTime<2021-04-04 02:30:00+11:00 AEDT Australia/Melbourne>

Examples of correct conversion:

brian@canidae:~$ date +%F_%T -d "2021-04-03T15:30Z"
2021-04-04_02:30:00
iex(13)> DateTime.shift_zone(~U[2021-04-03 15:30:00Z], "Australia/Melbourne")
{:ok, #DateTime<2021-04-04 02:30:00+11:00 AEDT Australia/Melbourne>}

https://www.timeanddate.com/worldclock/converter.html?iso=20210403T153000&p1=152&p2=1440

The fact that the DateTime library gets the correct value would suggest to me that the error is in the Timex library as opposed to the tzdata database.

@brianmay
Copy link
Author

brianmay commented Apr 5, 2021

This shows the correct transition from AEDT (day light savings time) to AEST (standard time). Ignore the fact the times are croseed out: https://www.timeanddate.com/worldclock/meetingtime.html?day=4&month=4&year=2021&p1=152&iv=1200

@brianmay
Copy link
Author

brianmay commented Apr 5, 2021

I forgot to say, this was timex version 3.7.3.

@bitwalker
Copy link
Owner

There were a few issues in the first few build versions of the 3.7.x series, have you tried again with the latest? Specifically, Timex.to_datetime(~U[2021-04-03 15:30:00Z], "Australia/Melbourne") produces the correct result as expected, as does DateTime.shift_zone/3 if you use Timex.Timezone.Database as the timezone database.

Using Timex.Timezone.convert isn't really intended as a public API, and using it directly like this is not the correct way to handle timezone conversions, despite the name, instead use one of the two options I mentioned above. Make sure you are using version 3.7.5.

@brianmay
Copy link
Author

brianmay commented Apr 6, 2021

Ooops. Sorry, looks like I made two mistakes:

  1. Contrary to what I said above, was using timex version 3.6.4. Getting confused with elixir dependancies.
  2. Got the wrong API for the test case. But the problem did occur with public API too.

I can't find any problems after upgrading to 3.7.5, so looks like it was fixed, and you were right to close it.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants