timex
timex copied to clipboard
Timezone MDT not supported for parsing (yet it works for formatting)
Steps to reproduce
format_str = "{YYYY}-{M}-{D} {h24}:{m}:{s} {Zabbr}"
{:ok, datetime} = DateTime.new(~D[2021-09-13], ~T[00:00:00.000], "America/Denver")
{:ok, d } = Timex.format(datetime, format_str) # this outputs MDT as the timezone, but it cannot parse the datetime back from that string.
IO.puts d # => "2021-9-13 00:00:00 MDT"
IO.inspect Timex.parse(d, format_str) # => {:error, :time_zone_not_found}
Description of issue
- Using the same input string, the formatted output should be able to be re-parsed to a date time.
- Clearly the library recognizes MDT as a valid date time because I do not have MDT anywhere in my code. It is correctly converting from America/Denver to MDT, but it cannot parse it back from MDT again.
- In the above example, the output of d should match the input of datetime. I believe the format call will return MDT part of the year and MST part of the year, but the end result or parsing it again should still return the same DateTime
I just encountered something similar when updating an app.
Timex.now("MDT") seemed to work in an iex session but in tests it would output {:error, :time_zone_not_found}, fixed it by using "America/Denver".
Elixir 1.13 Timex 3.7.6
This also affects Timex.parse(d, "…%Z…", :strftime) and appears to be a change that happened since 3.7.0. I can’t find the code that would have changed this in the history, so I’m wondering if it has to do with tzdata 1.0?
Seems like it started happening from this commit, which is included in 3.7.3 release
https://github.com/bitwalker/timex/commit/91cd0ed9daf5237cc2973d3625576fdd0e3cb12e
@bitwalker Just want to clarify, the example in the docs will fail since the TZ database change.
iex(7)> Timex.parse("Tue Mar 5 23:25:19 PST 2013", "{UNIX}")
{:error, :time_zone_not_found}
https://hexdocs.pm/timex/Timex.Format.DateTime.Formatters.Default.html
Is this expected?
I see 3.7.3 changelog mention potential breaking changes for incorrect behavior, and is Tue Mar 5 23:25:19 PST 2013 considered incorrect?
https://github.com/bitwalker/timex/blob/main/CHANGELOG.md#373
Got the same this morning with "PST". Same result with {:error, :time_zone_not_found} when using Timex.Timezone.convert.