bitwalker / bitwalker/timex

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

Open
#742 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
1.8k
Forks
407
PR merge metrics
No merged PRs in 30d

Description

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"]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.