1

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?

Bargain23
  • 1,863
  • 3
  • 29
  • 50
  • I'd expect so, yes - or rather, I'd expect it to return a GMT value if it's asked to convert a value which wouldn't fall in BST. Is there any reason you can't try it? I assume that `t` is an existing date/time value? I'm not an Elixir programmer, so I may be missing something, but the time zone conversion shouldn't depend on the *current* date/time at all. – Jon Skeet Apr 23 '19 at 14:07
  • @JonSkeet It's not dependent on the current date at all. I was just wondering how Timex performs the conversion for regions with daylight savings. – Bargain23 Apr 23 '19 at 14:09
  • I'm just asking because other than the period within BST, London time is the same as UTC+00. – Bargain23 Apr 23 '19 at 14:12
  • 1
    How about to create a date in November manually and try to convert? – Aleksei Matiushkin Apr 23 '19 at 14:14
  • 2
    I'd expect it to return something with "Europe/London (+0:00:00)" or similar. But it's definitely worth trying it - at which point if it's *not* what you expect, your question can be more specific. – Jon Skeet Apr 23 '19 at 14:16
  • 1
    As Jon said, it should work. When the tzdata application (a dependency of timex) starts, it will download information from https://www.iana.org/time-zones. It then stores that information in an ets table that timex uses to do the conversions. tzdata will also update this information periodically, so your application can run indefinately and still have up-to-date timezone information. – Justin Wood Apr 23 '19 at 14:56

1 Answers1

1

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>
Roman Boiko
  • 3,576
  • 1
  • 25
  • 41