Reputation: 714
I might not be understanding something here - but this could look more straight forward.
iex> {:ok, datetime_with_tz} = DateTime.now("Europe/London", Tzdata.TimeZoneDatabase)
{:ok, #DateTime<2020-05-02 21:57:11.136512+01:00 BST Europe/London>}
iex> DateTime.utc_now
~U[2020-05-02 20:57:21.869835Z]
//correct as it's already in utc
iex> DateTime.utc_now.utc_offset
0
// incorrect this should be 3600 i.e +01:00 hours of offset and not 0 .. ?
iex> datetime_with_tz.utc_offset
0
Upvotes: 2
Views: 560
Reputation: 447
That's because London is usually UTC+00:00, its currently +01:00 due to summer time (BST stands for British Summer Time).
DateTime have std_offset to deal with that.
iex(1)> {:ok, datetime_with_tz} = DateTime.now("Europe/London", Tzdata.TimeZoneDatabase)
iex(2)> datetime_with_tz.std_offset
3600
Upvotes: 4