Skip to content

Fix week of year numbering for {Wmon}, {Wsun}, %W and %U - #797

Open
dajiaohuang wants to merge 1 commit into
bitwalker:mainfrom
dajiaohuang:fix-week-of-year-numbering
Open

dajiaohuang wants to merge 1 commit into
bitwalker:mainfrom
dajiaohuang:fix-week-of-year-numbering

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary of changes

{Wmon}, {Wsun}, %W and %U return values that are off by one week in years beginning on a Sunday or Monday, and treat the days before the first weekstart day of the year as week 1 instead of week 0. This is the regression reported in #742; it was introduced when the week number calculation was reworked.

The previous implementation anchored the week boundary at the start of the year and then divided the shifted day number by 7, which only happens to be correct when the year starts on the weekstart day. The new implementation derives the week number from the day of the year and the weekday offset directly, so that days before the first weekstart day belong to week 0 and the following weeks are numbered from there, as strftime defines %W and %U.

Also corrects the documented range of these directives from 01..53/00..52 to 00..53.

Fixes #742

Checklist

  • New functions have typespecs, changed functions were updated
  • Same for documentation, including moduledocs
  • Tests were added or updated to cover changes
  • Commits were squashed into a single coherent commit
  • Notes added to CHANGELOG file which describe changes at a high-level

The week number was computed from a week boundary anchored at the start
of the year, which shifted every date by a week in years beginning on a
Sunday or Monday and produced values below the first full week.

Compute the number directly from the day of the year and the weekday
offset, so that days before the first weekstart day of the year are
week 0, matching strftime semantics. Correct the documented range of
the affected directives to 00..53.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant