Skip to content

fix(functions): DAYS360 reads the fictitious 29 February 1900 as February's end (#4012) - #4252

Open
gmrmad1 wants to merge 1 commit into
storytold:mainfrom
gmrmad1:fix/days360-1900-02-29-4012
Open

gmrmad1 wants to merge 1 commit into
storytold:mainfrom
gmrmad1:fix/days360-1900-02-29-4012

Conversation

@gmrmad1

@gmrmad1 gmrmad1 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What and why

DAYS360 with the US method is wrong around Excel's fictitious 29 February 1900 (serial 60). Excel's 1900 calendar has that day, so February 1900 ends on serial 60: the 28th (serial 59) is not a month end and must stay 28, while the 29th becomes 30. last_of_feb used the real calendar (days_in_month(1900, 2) == 28), so it did the opposite, giving DAYS360(59,61) = 1 and DAYS360(60,61) = 2 where Excel gives 3 and 1.

last_of_feb now treats 29 February 1900 as that month's end. The European method and other dates are untouched, and YEARFRAC basis 0 — which shares the helper and Excel's calendar — follows the same rule.

Evidence

New test date::tests::days360_across_the_fictitious_1900_02_29 asserts the issue's table:

Formula Before After
=DAYS360(59,61) 1 3
=DAYS360(60,61) 2 1
=DAYS360(59,61,TRUE) 3 3 (control)
=DAYS360(60,61,TRUE) 2 2 (control)
=DAYS360(61,62) 1 1 (control)

Without the helper change:

thread 'date::tests::days360_across_the_fictitious_1900_02_29' panicked:
got 1, expected 3
test result: FAILED. 0 passed; 1 failed

With it: date::tests — 19 passed, 0 failed.

Commands run

  • cargo test -p gridcraft-functions --lib date::tests — pass
  • a second run with the helper change temporarily removed — fail as above
  • cargo clippy -p gridcraft-functions --all-targets -- -D warnings — clean

All cargo commands ran via nice -n 19 with CARGO_BUILD_JOBS=2 CARGO_INCREMENTAL=0. Not run: workspace-wide CI, wasm.

Fixes #4012

Summary by CodeRabbit

  • Bug Fixes
    • Corrected month-end handling for February 1900 in the Excel 1900 date system.
    • Added coverage for US and European DAYS360 results around the fictitious date.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

last_of_feb now treats February 29, 1900, as month-end and does not treat February 28 as month-end. A new DAYS360 test checks US and European method results for serials 59–62.

Changes: DAYS360 February 1900 handling

Layer / File(s) Summary
February 1900 month-end handling
crates/functions/src/date.rs
last_of_feb recognizes February 29, 1900, as month-end. The new test checks US and European DAYS360 results across serials 59–62.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: echelon, dylanmtaylor

Merge Risk: Minimal · up to e9ca7

This change corrects DAYS360 results around Excel's fictitious 29 February 1900. Other dates are unaffected. The shared helper also affects YEARFRAC basis 0 for that narrow date range, and its native Excel behavior is unverified. Merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the DAYS360 fix in the date functions module, and the raw summary and objectives both describe a change to last_of_feb that treats serial 60 (29 February 1900) as February's end. The t…
Linked Issues check Passed [#4012] requires US-method DAYS360 to return 3 for (59,61) and 1 for (60,61), with the European method, DAYS360(61,62), and the 2024 leap-year control unchanged. The diff at crates/functions/src/date.…
Out of Scope Changes check Passed The change set has two source changes in crates/functions/src/date.rs. One is the last_of_feb special case for 1900. The other is a new unit test covering the issue table. Both connect directly to #40…
Full details: Title check

Explanation

The title names the DAYS360 fix in the date functions module, and the raw summary and objectives both describe a change to last_of_feb that treats serial 60 (29 February 1900) as February's end. The title accurately reflects the main change and the linked issue scope. It does not mention the YEARFRAC side effect, which is expected for a title.

Full details: Linked Issues check

Explanation

[#4012] requires US-method DAYS360 to return 3 for (59,61) and 1 for (60,61), with the European method, DAYS360(61,62), and the 2024 leap-year control unchanged. The diff at crates/functions/src/date.rs changes last_of_feb so that, for month 2 of year 1900, only day 29 is month end. Day 28 (serial 59) is no longer month end. Tracing the US method: (59,61) gives start day 28 and end day 1, so the result is 30 + (1 - 28) = 3. (60,61) gives start day 30 because serial 60 is treated as month end, so the result is 30 + (1 - 30) = 1. The European method does not call last_of_feb, so its results are unchanged. (61,62) is not a Feb-end case. The 2024 control is not in year 1900, so the fallback days_in_month path is used and the result is unchanged. The new test days360_across_the_fictitious_1900_02_29 asserts all five table rows, including the controls. I did not run the test. This verdict rests on reading the code and the arithmetic.

Full details: Out of Scope Changes check

Explanation

The change set has two source changes in crates/functions/src/date.rs. One is the last_of_feb special case for 1900. The other is a new unit test covering the issue table. Both connect directly to #4012. The PR states that YEARFRAC basis 0 shares last_of_feb and therefore follows the same 1900 rule. That effect comes from the shared helper, not from a separate feature. It only applies to dates in February 1900, and the PR description and issue scope disclose it. The change does not touch other functions or other dates. No unrelated change was found in the diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8bde636 and e9ca74f.

Files selected for processing: 1

  • crates/functions/src/date.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

emrahoksak pushed a commit to emrahoksak/girdcraft- that referenced this pull request Nov 18, 2026

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.

DAYS360 US method miscounts serials 59 and 60 across March 1, 1900

1 participant