Reputation: 3506
Dates are passed to the backend in UTC, and I want to convert time to a given TZ. I'm running into a bug as March 10th is in a different DST for UTC than my test TZ (America/Los_Angeles).
date = #DateTime<2019-03-10 02:25:19.464342Z>
timezone = Timezone.get("America/Los_Angeles", d2)
Timezone.convert(date, timezone)
Line 2 gives the following error
{:error, {:could_not_resolve_timezone, "America/Los_Angeles", 63719403919, :wall}}
I understand that this is because of DST, but at the given time, LA exists in some other datetime, which is what I'm looking for, how would I get that datetime?
Upvotes: 2
Views: 354
Reputation: 23091
How about Timezone.resolve/3
?
{:ok, date, _} = DateTime.from_iso8601("2019-03-10 02:25:19.464342Z")
unix = DateTime.to_unix(date)
timezone = Timex.Timezone.resolve("America/Los_Angeles", unix)
Timex.Timezone.convert(date, timezone)
Output:
#DateTime<2019-03-09 18:25:19.464342-08:00 PST America/Los_Angeles>
Upvotes: 0