enkr1

enkr1

What is the best way to handle timezone dynamically throughout your app?

I have done a round of research and found Timex library.

I am just here to gather more info & ideas on what is the best library/way to handle timezone in 2022.

Thought this thread might be useful for people working on the timezone-related task too!

Thank you so much in advance!

Most Liked

LostKobrakai

LostKobrakai

Generally it makes sense to shift tz conversion to the edge as far as possible (view layer, if not the client itself), but making everything (just) UTC within the backend is not necessarily sufficient, see UTC is not Your Saviour – Random Notes. Depending on the usecase knowing the local time of things can be just as important as knowing the UTC version of it.

As for more practical advice. Elixir core can handle datetimes quite well today. I’d rather opt for more focused libraries rather than timex. Elixir core for the data types. For timezone database tzdata or tz. For datetime parsing (if needed) date_time_parser or datix. For datetime formatting either Calendar.strftime or ex_cldr. And for storage base ecto tools of tz_datetime if the timezone needs to be retained or future datetimes are handled.

obsidienne

obsidienne

As I’m storing future datetimes, I’m using ex_cldr, tz_datetime and tz.
To help user find the correct timezone, I’m filtering the timezone select using the country were the event will be held.

Eiji

Eiji

@LostKobrakai Well … You did not got me this time. :smiling_imp:

I was talking about changing support everything on backend to UTC + client timezone (one but not explicitly said)… I never suggested to use UTC for multiple timezone handling. To be precise I was talking about move unnecessary logic to client which solves said problems without extra libraries (see code example).

I never worked on “1 of 10” edge cases mentioned in linked article, so I don’t have strict opinion on it. If I would work on chart in linked article most probably I would not even work on date time.

defmodule Example do
  defstruct ~w[day_num inserted_at hour name points]a
end

“Main” fields (i.e. day_num, hour and points) are important for graph.

The rest two fields are optional. inserted_at would be an UTC date time and under name could be anything like Tokyo or <shop name> in <city name>. With this I could manually preview edge cases of reported points like “jet lag” or “climate shock” in first days in new place like select * … where inserted_at > … and name = 'Tokyo' limit 720 (hours in 30 days).

Honestly I don’t see why in this case we need to work with any timezone when it’s not important from very start, so for me it’s not even topic about UTC vs local time. :smiley:


@enkr1 As you can see above, depending on use case the solution could be completely different. Please give us a bit more information and we can give more precise ideas!

LostKobrakai

LostKobrakai

Usually you see the “clock time” be called wall time.

dimitarvp

dimitarvp

Yeah, human language is hard. Much smarter people than me said that choosing the right word enables and empowers thinking about a problem. Sadly the reverse is even truer: choosing the wrong words cripples the potentially critical thought process about a problem.

No easy solution. Hence we all try and digest things into our own brain machine micro-code. :slight_smile:

Where Next?

Popular in Questions Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
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
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
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
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

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
Tee
can someone please explain to me how Enum.reduce works with maps
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
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement