bitwalker / bitwalker/timex

to_datetime without time zone no longer converts DateTime to UTC

Open
#721 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Elixir
Stars
1.8k
Forks
407
PR merge metrics
No merged PRs in 30d

Description

### Steps to reproduce

Updating some old code, I got bitten by this. In Timex 3.3.0, I could parse a timestamp in a known local time zone as follows:

```
Timex.parse!("2022-08-02T20:05", "{ISO:Extended}") |> Timex.to_datetime("America/Chicago") |> Time.to_datetime()
```

Now, in 3.7.8, the second `to_datetime` call does not change the time zone:

```
iex(4)> Timex.parse!("2022-08-02T20:05", "{ISO:Extended}") |> Timex.to_datetime("America/Chicago")
#DateTime<2022-08-02 20:05:00-05:00 CDT America/Chicago>
iex(5)> Timex.parse!("2022-08-02T20:05", "{ISO:Extended}") |> Timex.to_datetime("America/Chicago") |> Timex.to_datetime()
#DateTime<2022-08-02 20:05:00-05:00 CDT America/Chicago>
```

There is a simple workaround:

```
iex(6)> Timex.parse!("2022-08-02T20:05", "{ISO:Extended}") |> Timex.to_datetime("America/Chicago") |> Timex.to_datetime("Etc/UTC")
~U[2022-08-03 01:05:00Z]
```

Perhaps it was a deliberate change that `to_datetime` is a noop when passed an existing `DateTime` and no time zone argument, but the documentation does not make this clear. Either the old functionality of shifting to UTC needs to be restored, or the documentation needs to clearly cover this exception.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.