timex icon indicating copy to clipboard operation
timex copied to clipboard

`Timex.format/2` Wrong week number when using Wsun or %U

Open dmarkow opened this issue 2 years ago • 1 comments

In the example below, getting a week number using Monday as the start of the week works correctly: today, May 1st, is a new week. But if I try it with the week starting on a Sunday, it's actually identifying Saturday April 29th as the start of this week, when it should be April 30th. Here is the output for the last 4 days, Friday through Monday:

iex(54)> [~D(2023-04-28), ~D(2023-04-29), ~D(2023-04-30), ~D(2023-05-01)] |> Enum.map(&Timex.format!(&1, "%W", :strftime))
["17", "17", "17", "18"]
iex(55)> [~D(2023-04-28), ~D(2023-04-29), ~D(2023-04-30), ~D(2023-05-01)] |> Enum.map(&Timex.format!(&1, "%U", :strftime))
["16", "17", "17", "17"]
iex(56)> [~D(2023-04-28), ~D(2023-04-29), ~D(2023-04-30), ~D(2023-05-01)] |> Enum.map(&Timex.format!(&1, "{Wmon}"))
["17", "17", "17", "18"]
iex(57)> [~D(2023-04-28), ~D(2023-04-29), ~D(2023-04-30), ~D(2023-05-01)] |> Enum.map(&Timex.format!(&1, "{Wsun}"))
["16", "17", "17", "17"]

dmarkow avatar May 01 '23 16:05 dmarkow

Looks like this changed in 3.7.2.

Timex 3.7.1 has correct output:

iex(1)> [~D(2023-04-28), ~D(2023-04-29), ~D(2023-04-30), ~D(2023-05-01)] |> Enum.map(&Timex.format!(&1, "{Wsun}"))
["17", "17", "18", "18"]

Timex 3.7.2 has the wrong output:

iex(1)> [~D(2023-04-28), ~D(2023-04-29), ~D(2023-04-30), ~D(2023-05-01)] |> Enum.map(&Timex.format!(&1, "{Wsun}"))
["16", "17", "17", "17"]

dmarkow avatar May 01 '23 16:05 dmarkow