Nitrodist

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.

  1. I’ve looked at ex_cldr and ex_cldr_territories to no avail
  2. I have looked at the IANA tz data itself for a mapping of it to no avail
  3. 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

mayel

If you can get geocoordinates instead of just a state you could use this:

katafrakt

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

kip

ex_cldr Core Team

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

Where Next?

Popular in Questions Top

chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement