Nitrodist
Is there an elixir/erlang library that maps 4 character code regions to cities in the IANA Time Zone format? i.e. US-NY -> "America/New_York"
At my workplace we have a a module of code that does essentially a mapping of two character codes two a specific city in the IANA time zone database.
For example, we have this kind of code:
def tzdb_timezone("CA-ON"), do: "America/Toronto"
def tzdb_timezone("US-NC"), do: "America/New_York"
Does an existing elixir/erlang library do the same?
I’ve done some research on it.
- I’ve looked at ex_cldr and ex_cldr_territories to no avail
- I have looked at the IANA tz data itself for a mapping of it to no avail
- tz and tzdata to no avail
Any additional information or links to existing elixir libraries or Erlang libraries would be greatly appreciated! Thank you in advance.
Most Liked
mayel
If you can get geocoordinates instead of just a state you could use this:
katafrakt
Ontario from your example lies in 3 time zones. I don’t think you can do a mapping like that which would be generic enough.
kip
If you can provide a UN LOCODE then you can resolve the applicable timezone, or timezones, by calling Cldr.Timezone.fetch/1.
locode is quite useful in lots of applications so maybe that’s a good canonical approach for your requirements too?
Example
iex> Cldr.Timezone.fetch("usnyc")
{:ok, ["America/New_York", "US/Eastern"]}
iex> Cldr.Timezone.fetch("ausyd")
{:ok,
["Australia/Sydney", "Australia/ACT", "Australia/Canberra", "Australia/NSW"]}
iex> Cldr.Timezone.fetch("uslax")
{:ok, ["America/Los_Angeles", "US/Pacific", "US/Pacific-New", "PST8PDT"]}
iex> Cldr.Timezone.fetch("nope")
:error
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









