timezoneelixirtimex

Elixir - Timex detecting when British Summer Time starts and ends


I found out that Timex.Timezone.convert(t, "Europe/London") returns a DateTime object of this format: #<DateTime(2019-04-24T17:00:00 Europe/London (+01:00:00))>. My question is when BST ends in October, will Timex.Timezone.convert(t, "Europe/London") automatically adjust and return the UTC time?


Solution

  • Yes, it will return +00:00 GMT Europe/London instead of +01:00 BST Europe/London.

    As suggested in the comments, it's easy to check this: assuming that {:timex, "~> 3.0"} is added as a dependency, run

    $iex -S mix
    iex(1)> t = DateTime.from_naive!(~N[2019-11-01 13:26:08.003], "Etc/UTC")
    #DateTime<2019-11-01 13:26:08.003Z>
    iex(2)> Timex.Timezone.convert(t, "Europe/London")                      
    #DateTime<2019-11-01 13:26:08.003+00:00 GMT Europe/London>
    iex(3)> t = DateTime.from_naive!(~N[2019-10-01 13:26:08.003], "Etc/UTC")
    #DateTime<2019-10-01 13:26:08.003Z>
    iex(4)> Timex.Timezone.convert(t, "Europe/London")                      
    #DateTime<2019-10-01 14:26:08.003+01:00 BST Europe/London>