Harrygr

Harrygr

Formatting date and time in an email in the correct timezone

I’m want to send emails from my elixir/phoenix application that contains information about events stored in the database. Included in this information is the date and time of the event. The event times are stored in the DB as UTC timestamps. I also have lat/long coordinates of the event location in the DB.

Ideally in the email the event time would be formatted to be displayed in the timezone of the location where the event is being held.

e.g. if an event being held in Paris, France is at 2019-11-20T13:00:00Z this might be displayed in the email as “20 Nov 2019, 14:00 CET”.

Alternatively the time would be displayed in the recipient’s timezone. This is tricky though as I have no control over any client side date parsing etc in an email.

I’m aware of 3rd party APIs that can give a timezone from a lat/long but I’d like to avoid adding such a dependency.

I am also considering attaching an invite.ics to the email so that compatible email clients can parse it and display it in the recipient’s timezone.

Are there any good suggestions for solving this problem? I imagine it must be quite a common challenge.

Marked As Solved

kip

kip

ex_cldr Core Team

There is an Elixir library tz_world that uses the underlying data from evansiroky/timezone-boundary-builder. The current hex version relies on Ecto and PostGIS but:

Using my fork:

iex> TzWorld.timezone_at 3.25, 45.1                            
{:ok, "Europe/Paris"}

Also Liked

danschultzer

danschultzer

Pow Core Team

There’s also geotz based on the excellent dark sky tz-lookup library. Was built and used for a platform in production a while back, where we had to fetch many timezones dynamically.

Edit: It hasn’t been released on hex, we just used the github source.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
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
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement