Skip to content

fix(date): compute %C and %y from the numeric year - #961

Merged
harttle merged 1 commit into
harttle:masterfrom
youdie006:fix-date-century-year
Sep 29, 2026
Merged

harttle merged 1 commit into
harttle:masterfrom
youdie006:fix-date-century-year

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

%C and %y slice the year string (src/util/strftime.ts:46 and :113), so they are wrong for years that are not four digits, and %y returns a string that the - and _ flags cannot unpad. {{ d | date: "%C|%y|%-y|%_y" }}:

year master this PR Ruby strftime
2005 20|05|05|05 20|05|5| 5 20|05|5| 5
2016 20|16|16|16 same same
999 99|9|9|9 09|99|99|99 09|99|99|99

This computes both from the numeric year and adds C and y to padWidths, as #958 did for %U/%W. Plain %C and %y output for four-digit years is unchanged; the visible change there is %-y/%_y for years like 2005.

The new test in src/util/strftime.spec.ts fails on master and passes here. npm test (TZ=Asia/Shanghai, 1672 tests; src and filter tests also under America/New_York), npm run lint, tsc --noEmit and npm run build pass on Node 22.

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

Both were sliced from the year string, so years with other than four
digits gave the wrong century and two-digit year, and %y was a string
that the - and _ flags could not unpad. Compute them arithmetically and
pad them to two digits, matching Ruby's strftime.
@harttle
harttle merged commit e68514f into harttle:master Sep 29, 2026
14 checks passed
@harttle

harttle commented Sep 29, 2026

Copy link
Copy Markdown
Owner

@all-contributors please add @youdie006 for code

@allcontributors

Copy link
Copy Markdown
Contributor

@harttle

@youdie006 already contributed before to code

github-actions Bot pushed a commit that referenced this pull request Oct 1, 2026
# [10.30.0](v10.29.0...v10.30.0) (2026-10-01)

### Bug Fixes

* **base64_encode:** encode large input in browser builds ([#969](#969)) ([8aace78](8aace78)), closes [#967](#967)
* **date:** compute %C and %y from the numeric year ([#961](#961)) ([e68514f](e68514f))
* **date:** compute %U and %W week numbers like strftime ([#958](#958)) ([0587ca8](0587ca8))
* trim custom characters by Unicode code point ([#955](#955)) ([3fe244f](3fe244f))
* **truncatewords:** ignore leading whitespace when counting words ([#954](#954)) ([65e200e](65e200e))
* **url_decode:** keep %2B as a literal plus when decoding ([#939](#939)) ([9af92f5](9af92f5))

### Features

* await promises returned by Drop.valueOf() ([#948](#948)) ([#953](#953)) ([#959](#959)) ([7dfa76b](7dfa76b))
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 10.30.0 🎉

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