feat: add %g format code for ISO 8601 week-based year#129
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
feat: add %g format code for ISO 8601 week-based year#129Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
Add format_g() which returns the 2-digit ISO 8601 week-based year, complementing the existing %V (ISO week number). The ISO week year differs from the calendar year at year boundaries — e.g., Dec 31 2025 (week 01) has ISO week year 26, while Jan 1 2016 (week 53) has ISO week year 15. Refactors format_V to share a common _iso_week_year() helper that computes both the ISO week year and week number via the Thursday-based algorithm. 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
Adds
%gformat code that returns the 2-digit ISO 8601 week-based year.Why
With
%V(ISO week number) recently merged, the natural companion%g(ISO week year) was missing. The ISO week year differs from the calendar year at year boundaries — e.g., Dec 31, 2025 is in week 01 of 2026, and Jan 1, 2016 is in week 53 of 2015. Without%g, users who format ISO week dates (%g-W%V) have to compute the year themselves.Note: POSIX uses
%Gfor the 4-digit ISO week year, but TimeDate's%Gis already taken by the GPS week number.%g(2-digit) is the available complement.How
Extracted a shared
_iso_week_year()helper fromformat_Vthat returns both the ISO week year and week number using the Thursday-based algorithm.format_Vandformat_gboth delegate to it.Testing
%gto existing English timestamp block (mid-year, trivial case)%g=26,%V=01(ISO year > calendar year)%g=15,%V=53(ISO year < calendar year)%g=15,%V=01(ISO year > calendar year)🤖 Generated with Claude Code