timex icon indicating copy to clipboard operation
timex copied to clipboard

could_not_resolve_timezone error when converting a date during DST changeover

Open travelmassive opened this issue 3 years ago • 3 comments

I know this has been brought up in previous issues #555 and #625 but this doesn't seem to be resolved in the latest release 3.7.6 so I am creating a new issue.

Steps to reproduce

Convert a date between 2am and 3am on 3 October 2021 to "Australia/Melbourne" timezone.

Example:

~N[2021-10-03 02:31:07] |> Timex.Timezone.convert("Australia/Melbourne")

Output:

{:error, {:could_not_resolve_timezone, "Australia/Melbourne", 63800447467, :wall}}

This looks to be a DST issue, because the following (an hour earlier, before the DST switch) works:

~N[2021-10-03 01:31:07] |> Timex.Timezone.convert("Australia/Melbourne")

Output:

#DateTime<2021-10-03 01:31:07+10:00 AEST Australia/Melbourne>

Daylight saving time Melbourne began at 2:00 am on Sunday, 3 October 2021. The error occurs any trying to convert a date anytime between 2am and 3am.

What are the expected results?

I expect the date will be converted to a timezone without an error regardless of whether the time is in a DST changeover period or not for the given timezone.

Thanks for any assistance! - Ian

travelmassive avatar Oct 15 '21 01:10 travelmassive

iex(11)> ~N[2021-03-14 01:59:59] |> Timex.Timezone.convert("America/Chicago")
#DateTime<2021-03-14 01:59:59-06:00 CST America/Chicago>
iex(12)> ~N[2021-03-14 02:00:00] |> Timex.Timezone.convert("America/Chicago")
{:error, {:could_not_resolve_timezone, "America/Chicago", 63782906400, :wall}}
iex(13)> ~N[2021-03-14 02:59:59] |> Timex.Timezone.convert("America/Chicago")
{:error, {:could_not_resolve_timezone, "America/Chicago", 63782909999, :wall}}
iex(14)> ~N[2021-03-14 03:00:00] |> Timex.Timezone.convert("America/Chicago")
#DateTime<2021-03-14 03:00:00-05:00 CDT America/Chicago>

I've also caught it. It seems very surprising when out of context.

etehtsea avatar Jan 20 '22 09:01 etehtsea

This bit me today:

iex(5)> ~N[2022-03-13 02:37:00] |> Timex.to_datetime("America/Los_Angeles")
{:error, {:could_not_resolve_timezone, "America/Los_Angeles", 63814358220, :wall}}

edennis avatar Mar 03 '22 10:03 edennis

+1 as this bit us in prod.

STR

  1. Set your local machine time to 4/3/2022 @ 2:30am UTC
  2. Start the console and run `Timex.Timezone.get("America/Mexico_City")
iex(1)> DateTime.utc_now()
~U[2022-04-03 02:33:27.785095Z]
iex(2)> Timex.Timezone.get("America/Los_Angeles"
#<TimezoneInfo(America/Los_Angeles - PDT (-07:00:00))>
iex(3)> Timex.Timezone.get("America/Mexico_City")
{:error, {:could_not_resolve_timezone, "America/Mexico_City", 63816172439, :wall}}

Though in my case we're not converting a date. We're asking for the abbreviation of a particular TZ but in this case we get the error tuple which is not ideal.

heroinbob avatar Apr 11 '22 17:04 heroinbob