Fix week of year numbering for {Wmon}, {Wsun}, %W and %U - #797
Open
dajiaohuang wants to merge 1 commit into
Open
dajiaohuang wants to merge 1 commit into
dajiaohuang wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of changes
{Wmon},{Wsun},%Wand%Ureturn 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
%Wand%U.Also corrects the documented range of these directives from
01..53/00..52to00..53.Fixes #742
Checklist