Skip to content

Timezone MDT not supported for parsing (yet it works for formatting) #686

Open

Description

@AdamLeMmon01

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

Activity

  1. tfantina commented on Dec 22, 2021

    @tfantina

    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

  2. halostatue commented on Apr 20, 2023

    @halostatue

    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?

  3. darwin67 commented on Jul 12, 2023

    @darwin67

    Seems like it started happening from this commit, which is included in 3.7.3 release
    91cd0ed

    @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

  4. noozo commented on Jul 13, 2023

    @noozo

    Got the same this morning with "PST". Same result with {:error, :time_zone_not_found} when using Timex.Timezone.convert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions