Skip to content

Pad the century in %C to two digits - #27

Merged
alphp merged 1 commit into
alphp:masterfrom
samipuro:fix/century-padding
Nov 24, 2026
Merged

alphp merged 1 commit into
alphp:masterfrom
samipuro:fix/century-padding

Conversation

@samipuro

@samipuro samipuro commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

%C returned the century as the float result of floor(), so it was not padded. For the year 0001 it returned 0 instead of 00, and for 0999 9 instead of 09, although the format is documented as two digits.

The century is now calculated with intdiv() and formatted with sprintf('%02d'). Modern years are unchanged. %_C now pads with a space, and %-C still removes the padding.

Tests are added to testYearFormats for the years 0001, 0999 and 1000 and for %-C and %_C.

@samipuro
samipuro force-pushed the fix/century-padding branch from eec9d6d to aa9e2ed Compare November 23, 2026 12:11
@alphp
alphp merged commit 3776e70 into alphp:master Nov 24, 2026
15 checks passed
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.

2 participants