fix: correct %V ISO week at leap year boundaries#133
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: correct %V ISO week at leap year boundaries#133Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
When a date falls in early January and its ISO Thursday belongs to the previous year, format_V adjusts $thu by adding the previous year's day count. If that previous year is a leap year (366 days), the adjusted $thu equals the current year's $ylen (365), incorrectly triggering the year-end check and returning week 01 instead of the correct week 53. Fix: only apply the year-end check ($thu >= $ylen) when Thursday was NOT already adjusted to the previous year. The year-end check is meant for late-December dates whose Thursday falls in the next year, not for early-January dates already handled by the previous-year adjustment. Affected dates: Jan 1-3 of any year where: - January 1 is Thursday, Friday, Saturday, or Sunday, AND - the previous year is a leap year Example: 2021-01-01 (Fri) returned %V=01 instead of %V=53. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
What
Fixes
%V(ISO 8601 week number) returning01instead of the correct week number for early-January dates when the previous year is a leap year.Why
When a date like 2021-01-01 (Friday) belongs to ISO week 53 of 2020,
format_Vcorrectly identifies that Thursday falls in the previous year and adjusts by adding 2020's 366 days. But the adjusted value (365) then matches the current year's day count (365), incorrectly triggering the year-end check and returning week 01.The year-end check (
$thu >= $ylen) is meant for late-December dates whose Thursday is in the next year — it should never apply when Thursday was already adjusted to the previous year.How
Move the year-end boundary check into an
elsebranch so it only applies when no previous-year adjustment was made. The$thu < 0path (previous year) and$thu >= $ylenpath (next year) are mutually exclusive by definition.Testing
strftime("%V")for 14 year-boundary dates — all match🤖 Generated with Claude Code