Skip to content

fix(date): pad %Y to 4 digits - #978

Merged
harttle merged 1 commit into
harttle:masterfrom
youdie006:fix/strftime-pad-year
Oct 27, 2026
Merged

harttle merged 1 commit into
harttle:masterfrom
youdie006:fix/strftime-pad-year

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

%Y has no entry in padWidths (src/util/strftime.ts:50), so a year below 1000 is printed unpadded. {{ s | date: "%Y-%m-%d" }}:

input master this PR Ruby strftime
0001-01-01T00:00:00Z (Go/C# zero time) 1-01-01 0001-01-01 0001-01-01
0045-06-15T00:00:00Z 45-06-15 0045-06-15 0045-06-15
0999-12-31T00:00:00Z 999-12-31 0999-12-31 0999-12-31

This adds Y: 4, and when zero-padding a negative value keeps the sign in front, so %05Y of year -5 gives -0005 (Ruby) instead of 00-5. A bare %Y of a negative year now gives -005; Ruby gives -0005 there, which would need a special case for Y.

The new test next to the %y ones fails on master. npm run lint passes, and npm test passes (1701 tests) with TZ set to Etc/GMT, Asia/Shanghai and America/New_York.

Written with AI assistance (Claude); I have reviewed the change.

%Y had no pad width, so a year below 1000 printed unpadded: the zero time
0001-01-01 formatted as 1-01-01 where Ruby gives 0001-01-01. Pad it to 4,
and keep the sign in front when padding a negative value with zeros.
@harttle
harttle merged commit 95a2eed into harttle:master Oct 27, 2026
14 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
## [10.30.1](v10.30.0...v10.30.1) (2026-10-28)

### Bug Fixes

* apply outputEscape to {% echo %} ([46ab5d8](46ab5d8))
* **array_to_sentence_string:** coerce non-array input with toArray ([#968](#968)) ([e843466](e843466)), closes [#964](#964)
* **base64_decode:** throw on invalid input in every build ([#971](#971)) ([83bbfe0](83bbfe0)), closes [#965](#965)
* **date_to_rfc822:** use English day and month names ([#974](#974)) ([e94a1c4](e94a1c4)), closes [#973](#973)
* **filters:** round must not alter large or high-precision numbers ([#980](#980)) ([ea22af4](ea22af4)), closes [hi#precision](https://github.com/hi/issues/precision)
* **filters:** truncate and slice must not split surrogate pairs ([#981](#981)) ([57016eb](57016eb)), closes [String#length](https://github.com/String/issues/length) [String#slice](https://github.com/String/issues/slice)
* pad %Y to 4 digits like Ruby ([#978](#978)) ([95a2eed](95a2eed))
* **security:** apply outputEscape to {% cycle %} ([#984](#984)) ([2e1ebe0](2e1ebe0))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 10.30.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants