Skip to content

fix(date): use proleptic Gregorian leap years for BC dates and gregorian-based calendars - #10979

Open
waw666waw666 wants to merge 1 commit into
adobe:mainfrom
waw666waw666:fix-gregorian-bc-leap-years
Open

waw666waw666 wants to merge 1 commit into
adobe:mainfrom
waw666waw666:fix-gregorian-bc-leap-years

Conversation

@waw666waw666

@waw666waw666 waw666waw666 commented Nov 17, 2026 •

Copy link
Copy Markdown

Closes N/A (no existing issue)

Summary

GregorianCalendar decides leap years from the era year (date.year) instead of the extended (astronomical) year that gregorianToJulianDay already uses. In the BC era those are different numbers: 1 BC is year 0, 5 BC is year -4. So in BC every year whose era number is divisible by 4 (4 BC, 8 BC, ...) is treated as leap, and the real leap years (1 BC, 5 BC, ...) are not.

"Proleptic" here means extending the Gregorian leap-year rule backwards to dates before the calendar existed, using astronomical year numbering (1 BC = year 0). That is what gregorianToJulianDay and ISO 8601 / Temporal already do; this PR makes the rest of GregorianCalendar follow the same rule.

Because toJulianDay does use the extended year, the two directions disagree and BC dates come out wrong:

new CalendarDate('BC', 1, 2, 28).add({days: 1});  // BC 1-03-01, expected BC 1-02-29
new CalendarDate('BC', 40, 1, 1).add({days: 59}); // BC 40-02-29, but 40 BC is not a leap year

let cal = new GregorianCalendar();
cal.fromJulianDay(cal.toJulianDay(new CalendarDate('BC', 1, 2, 28)) + 1); // BC 1-02-28 again

Walking every day from 10 BC to 10 AD, toJulianDay(fromJulianDay(jd)) !== jd for about 10 days in each affected BC year, and some days map to the same date twice.

Separately, BuddhistCalendar, TaiwanCalendar and JapaneseCalendar override getDaysInMonth to convert to a gregorian year first, but they inherit getDaysInYear unchanged, so it runs the leap-year rule on the Buddhist/Minguo/era year:

let buddhist = new BuddhistCalendar();
buddhist.getDaysInYear(toCalendar(new CalendarDate(2024, 6, 1), buddhist)); // 365 (BE 2567), expected 366

Same for Taiwan (Minguo 113) and Japanese (Reiwa 6).

Fix:

  • GregorianCalendar.fromJulianDay, getDaysInMonth and getDaysInYear use the extended year for the leap-year check, matching gregorianToJulianDay. AD dates are unchanged since the extended year equals the era year there.
  • BuddhistCalendar, TaiwanCalendar and JapaneseCalendar override getDaysInYear the same way they already override getDaysInMonth.

📝 Test Instructions

To verify by hand, check out this branch, run yarn install, then open a Node REPL or a scratch file that imports from packages/@internationalized/date/src:

  1. BC leap day: new CalendarDate('BC', 1, 2, 28).add({days: 1}).toString(). On main this gives March 1 (1 BC treated as a common year); on this branch it gives February 29, 1 BC.
  2. Non-leap BC year: new CalendarDate('BC', 40, 1, 1).add({days: 59}). On main this lands on February 29 of 40 BC, which does not exist; on this branch it lands on March 1.
  3. Round trip: with let cal = new GregorianCalendar(), cal.fromJulianDay(cal.toJulianDay(new CalendarDate('BC', 1, 2, 28)) + 1) should return BC 1-02-29, not BC 1-02-28 again.
  4. Gregorian-based calendars: new BuddhistCalendar().getDaysInYear(toCalendar(new CalendarDate(2024, 6, 1), new BuddhistCalendar())) should return 366 (2024 is a leap year). Same check with TaiwanCalendar and JapaneseCalendar.
  5. AD dates are untouched: e.g. new CalendarDate(2024, 2, 28).add({days: 1}) is still 2024-02-29 and new CalendarDate(2023, 2, 28).add({days: 1}) is still 2023-03-01.

You can also cross-check any of these against @js-temporal/polyfill (ISO calendar for BC dates, buddhist/roc/japanese for the others), which is how I found the bug.

New unit tests in conversion.test.js and manipulation.test.js cover the same cases; CI runs the full yarn test and yarn lint.

Release impact

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

✅ PR Checklist

  • I followed the contributing guide.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

AI disclosure: I used an AI assistant to help find and write this fix; I reviewed and tested every change.

🧢 Your Project

Personal

…calendars

GregorianCalendar checked leap years against the era year, so BC years were
treated as leap when their era year was divisible by 4 (4 BC, 8 BC, ...) and
real leap years (1 BC, 5 BC, ...) were not. This broke fromJulianDay,
getDaysInMonth and getDaysInYear for BC dates. Buddhist, Taiwan and Japanese
calendars also inherited getDaysInYear without converting their year to a
gregorian year first.
@snowystinger snowystinger added waiting on author Waiting on Issue Author unsigned CLA labels Nov 17, 2026
@snowystinger

Copy link
Copy Markdown
Member

You need to sign the CLA

This word "proleptic" is in the title and never mentioned again, please explain.

Testing description section isn't about what unit tests to run, it's about how a human can verify the code while reviewing the PR. Please update it accordingly.

I did not run the full monorepo yarn test / yarn lint

you should be able to do this, especially as a human, they don't take very long. good news, the CI ran them, they are passing.

@waw666waw666 waw666waw666 changed the title fix(date): use proleptic leap years for BC dates and gregorian-based calendars fix(date): use proleptic Gregorian leap years for BC dates and gregorian-based calendars Nov 17, 2026
@waw666waw666

Copy link
Copy Markdown
Author

Thanks for the review. I've signed the CLA, added a sentence to the summary explaining "proleptic" (the Gregorian leap-year rule extended back to BC dates with astronomical year numbering, as gregorianToJulianDay and Temporal already do), and rewrote the Test Instructions as manual steps a reviewer can run, with expected results on main vs this branch. Noted on running the full yarn test / yarn lint locally next time.

@snowystinger

Copy link
Copy Markdown
Member

try to get CLA to take hold

@snowystinger snowystinger reopened this Nov 17, 2026
@snowystinger snowystinger removed waiting on author Waiting on Issue Author unsigned CLA labels Nov 17, 2026
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