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

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
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
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement