Skip to content

feat: add %g format code for ISO 8601 week-based year#129

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/add-format-g-iso-week-year
Draft

feat: add %g format code for ISO 8601 week-based year#129
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/add-format-g-iso-week-year

Conversation

@Koan-Bot
Copy link
Copy Markdown

@Koan-Bot Koan-Bot commented May 1, 2026

What

Adds %g format 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 %G for the 4-digit ISO week year, but TimeDate's %G is already taken by the GPS week number. %g (2-digit) is the available complement.

How

Extracted a shared _iso_week_year() helper from format_V that returns both the ISO week year and week number using the Thursday-based algorithm. format_V and format_g both delegate to it.

Testing

  • Added %g to existing English timestamp block (mid-year, trivial case)
  • Added 3 year-boundary test cases:
    • Dec 31, 2025 → %g=26, %V=01 (ISO year > calendar year)
    • Jan 1, 2016 → %g=15, %V=53 (ISO year < calendar year)
    • Dec 29, 2014 → %g=15, %V=01 (ISO year > calendar year)
  • Full test suite passes (all files)

🤖 Generated with Claude Code

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>
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.

1 participant