Time zones are a weird topic.
To get the values you want from Tzdata
I would go this way.
iex(17)> d = DateTime.utc_now()
~U[2020-01-26 09:06:46.250947Z]
iex(18)> iso_days = Calendar.ISO.naive_datetime_to_iso_days(d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond)
{737815, {32806250947, 86400000000}}
iex(19)> Tzdata.TimeZoneDatabase.time_zone_period_from_utc_iso_days(iso_days, "Europe/Berlin") {:ok,
%{
from_wall: ~N[2019-10-27 02:00:00],
std_offset: 0,
until_wall: ~N[2020-03-29 02:00:00],
utc_offset: 3600,
zone_abbr: "CET"
}}
This gives you the utc_offset
and std_offset
(DST) for the current point in time. Both values could be change over time. For utc_offset
it is not so usually but it can happen. @LostKobrakai mentioned this in his comment about the situation in the EU.
For me it is also weird to select a time zone by utc offset, because that will group many countries with different rules for the DST. In some edge cases it can be difficult to say if you in a zone with UTC -11
or UTC +13
.
For a better user experience in your time zone selector you could provide more cities. Data for that approach can be found at http://www.geonames.org/export/
With this data you can build something like this https://www.timeanddate.com/worldclock/converter.html