Skip to content

fix: keep sign when zero-padding negative years in format('YYYY') (#2722) - #3223

Open
anas510 wants to merge 1 commit into
iamkun:devfrom
anas510:fix/format-negative-year-padding
Open

anas510 wants to merge 1 commit into
iamkun:devfrom
anas510:fix/format-negative-year-padding

Conversation

@anas510

@anas510 anas510 commented Sep 18, 2026

Copy link
Copy Markdown

Fixes #2722

padStart counted the minus sign as a character to pad around, so negative (BC) years rendered wrongly:

  • dayjs('-000001').format('YYYY') → 00-1 (now -0001)

  • dayjs('-000010').format('YYYY') → 0-10 (now -0010)

  • dayjs('-000100').format('YYYY') → -100 (now -0100)

  • padStart now pads the absolute value and re-applies the sign, as Moment's zeroFill does.

  • No change for non-negative inputs; duration().format() with negative components benefits the same way (0-1 → -01).

  • Bundle size +~20 B (2.81 KB, under the 2.99 KB limit).

Out of scope: years 0–99 are still shifted by new Date(y, m, d) (#2591); YY for negative years is unchanged.

This branch has not been deployed

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

BC year formatted as 'YYYY' abnormally

2 participants