Skip to content

Fix 31 December converting to day 0 of the next year with leapYear1900 - #1873

Open
aliassar wants to merge 8 commits into
handsontable:developfrom
aliassar:fix/1793-leap-year-1900-dec-31
Open

aliassar wants to merge 8 commits into
handsontable:developfrom
aliassar:fix/1793-leap-year-1900-dec-31

Conversation

@aliassar

@aliassar aliassar commented Nov 3, 2026 •

Copy link
Copy Markdown

Context

With leapYear1900: true, which is the setup the Excel compatibility guide recommends, 31 December of 32 years between 1900 and 2200 (for example 2036, 2040 and 2069) converts to day 0 of January of the next year. So =DAY(DATE(2036, 12, 31)) returns 0 and =EOMONTH(DATE(2036, 12, 31), 0) returns 31 January 2037. numberToSimpleDate estimates the year as floor(dateNumber / 365.2425). When that estimate was one year too high, the downward correction checked the start of the year before the estimate instead of the estimate itself, so it never fired. The fix is the one-token change suggested in the issue.

How did you test your changes?

  • Added hyperformula/test/leap-year-1900.spec.ts. 5 of its 6 cases fail on develop, and all 6 pass with the fix.
  • In hyperformula/, npx jest passes 2 suites and 10 tests. npx tsc --noEmit is clean, and npx eslint on the changed files reports 0 errors.
  • A throwaway script round-tripped every date from 1600 to 9999 with five nullDate values and both leapYear1900 settings. develop had 640 mismatches, all on 31 December and all with leapYear1900: true. With the fix there are 0.

Compatibility with Excel and Google Sheets

Not checked in Excel or Google Sheets. The fix only makes the date number convert back to the date it came from: =DAY(DATE(2036, 12, 31)) now returns 31 (was 0) and =TEXT(EOMONTH(DATE(2036, 12, 31), 0), "yyyy-mm-dd") returns 2036-12-31 (was 2037-01-31).

Public API changes

None.

Out of scope and follow-ups

None.

Types of changes

  • Breaking change (existing functionality no longer works as before) – agreed with the maintainers
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Related issues

  1. Fixes numberToSimpleDate returns day 0 for 31 December of some years when leapYear1900 is true #1793

Checklist


Note

Low Risk
Narrow one-line change in date serial decoding with dedicated tests; no public API changes.

Overview
Fixes 31 December in some years (e.g. 2036, 2040, 2069) mapping to day 0 of the following January when leapYear1900: true, so =DAY(DATE(2036, 12, 31)) and related functions (MONTH, EOMONTH, etc.) align with Excel-style serial dates again.

In DateTimeHelper.numberToSimpleDate, the downward year adjustment after the 365.2425 estimate now compares against January 1 of the estimated year instead of year − 1, so an overestimated year is decremented when it should be.

Adds hyperformula/test/leap-year-1900.spec.ts (six cases) and a CHANGELOG entry for #1793.

Reviewed by Cursor Bugbot for commit bcf3769. Bugbot is set up for automated code reviews on this repo. Configure here.

numberToSimpleDate corrected an overshooting year estimate by comparing
the start of the previous year instead of the start of the estimated
year, so with leapYear1900 enabled the 31st of December of 32 years
between 1900 and 2200 (e.g. 2036 and 2040) came out as day 0 of January.

Fixes handsontable#1793

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cla-external-contractor-signup

Copy link
Copy Markdown

@aliassar Thank you very much for taking the time to prepare the pull request. There's one thing holding us back from using those changes in production — could you please sign the CLA: https://cla.handsontable.com/sign?pr=handsontable%2Fhyperformula%231873
Thanks in advance 🙇

@cla-external-contractor-signup

Copy link
Copy Markdown

@aliassar Thank you for signing the CLA! The status check has been updated and your pull request is now unblocked. 🎉

aliassar and others added 3 commits November 11, 2026 15:10
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@handsontable-pr-review handsontable-pr-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Medium risk: One-condition change in the core date serial-to-date conversion used by all date functions, but it is narrow, mathematically sound (the 365.2425 estimate is off by at most ±1 year, so a single correction step suffices), and verified by round-trip testing across 1600–9999 with multiple nullDate values.

Full review: no issues found.

Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).

Develop now validates license keys, so the leap-year test uses TEST_LICENSE_KEY like the other suites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@handsontable-pr-review handsontable-pr-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Medium risk: A one-line change to core date serial-number decoding (numberToSimpleDate) that affects DAY/MONTH/YEAR/EOMONTH/YEARFRAC and other date functions, but it is a narrow correction verified by an exhaustive round-trip test across the full date range.

Full review: no issues found.

Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).

aliassar and others added 3 commits November 23, 2026 21:31
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the changelog entry to the new Unreleased section after the 4.0.0 release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant