bitwalker / timex

A complete date/time library for Elixir projects.
https://hexdocs.pm/timex
MIT License
1.76k stars 379 forks source link

Start of day fails to handle change from daylight saving #725

Closed chriseyre2000 closed 2 years ago

chriseyre2000 commented 2 years ago

Steps to reproduce

Timex.parse!("2022-10-29 09:17:42.642885+01:00 BST Europe/London", "{ISO:Extended}") |> Timex.Timezone.convert("Europe/London") |> Timex.shift(hours: -8) |> Timex.shift(days: 1) |> Timex.beginning_of_day()

This returns:

** (Timex.ConvertError) unable to convert value, insufficient date/time information (timex 3.7.9) lib/datetime/map.ex:41: Timex.Protocol.Map.beginning_of_day/1

We actually used Timex.now("Europe/London"), but the above recreates the issue

Description of issue

I expected it to return the start of the day as would have happened an hour later.

DateTime<2022-10-30 00:00:00.000000+01:00 BST Europe/London>

Timex.parse!("2022-10-29 09:17:42.642885+01:00 BST Europe/London", "{ISO:Extended}") |> Timex.Timezone.convert("Europe/London") |> Timex.shift(hours: -7) |> Timex.shift(days: 1) |> Timex.beginning_of_day()

DateTime<2022-10-30 00:00:00.000000+01:00 BST Europe/London>

The values for -7 and -9 are correct, it only fails for -8

chriseyre2000 commented 2 years ago

I had failed to handle AmbiguousDateTime.