Skip to content

Pad the ISO-8601 year in %g to two digits - #30

Open
samipuro wants to merge 1 commit into
alphp:masterfrom
samipuro:fix/iso-year-two-digits
Open

samipuro wants to merge 1 commit into
alphp:masterfrom
samipuro:fix/iso-year-two-digits

Conversation

@samipuro

@samipuro samipuro commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

%g took the last two characters of DateTime::format('o'), which is not padded, so ISO-8601 years 0 to 9 came out as a single digit. strftime('%g', new DateTime('0005-06-15')) returned 5 instead of 05, although %g is two digits, like %y.

The ISO-8601 year is now formatted with sprintf('%02d'), as %C is. Other years are unchanged, %-g removes the padding and %_g pads with a space.

Tests are added to testYearFormats for the years 0005 and 2010 (ISO year 2009) and for %-g and %_g.

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