Skip to content

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

Open
@dmarkow

Description

@dmarkow

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions