Skip to content

Fix DAYS360 US method when both dates are last day of February - #2406

Closed
Silvertree2010 wants to merge 1 commit into
storytold:mainfrom
Silvertree2010:fix/h1884-days360-us-method-returns-2-when
Closed

Silvertree2010 wants to merge 1 commit into
storytold:mainfrom
Silvertree2010:fix/h1884-days360-us-method-returns-2-when

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/functions/src/date.rs:270-284 (days360_core) (no existing issue): DAYS360 (US method) returns -2 when both dates are the last day of February.

Cause

Cause

In the US method of DAYS360, a start date on the last day of February was moved to day 30, but an end date on the last day of February was never moved. DATE(2021,2,28) to DATE(2021,2,28) was therefore counted as 30 to 28 and returned -2.

Fix

Fix

In days360_core, the end day is now set to 30 when both dates are the last day of February. This check runs before the start day is adjusted.

Verified

The added assertion in the existing DAYS360 tests in crates/functions/src/date.rs fails without the fix (returns -2) and passes with it. Run with cargo test -p gridcraft-functions --lib date.

Verified

  • Regression test date::tests::day_counts: fails on main without the fix and passes with it (cargo test -p gridcraft-functions --lib day_counts).
  • cargo xtask ci passes.

Not changed

Not changed

The European method, the 30/360 helper in financial.rs, YEARFRAC and the securities functions are unchanged.

🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the US-method DAYS360 calculation for dates that are both the last day of February. When the start and end dates are the same, the calculation now returns zero days. This keeps the result consistent for this February month-end case.

Found while testing crates/functions/src/date.rs:270-284 (days360_core)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b8771d5 and 8278063.

Files selected for processing: 1
  • crates/functions/src/date.rs

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

Walkthrough

The US method in days360_core now sets the ending day to 30 when both dates are the last day of February. The DAYS360 tests check that February 28, 2021 to the same date returns zero days.

Changes: DAYS360 February end-date handling

Layer / File(s) Summary
US method handling and test
crates/functions/src/date.rs
When both dates are the last day of February, days360_core sets the ending day to 30. A test checks that February 28, 2021 to the same date returns zero days.

Priority: Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: marekspodbiedry

Merge Risk: Minimal · up to 82780

The localized DAYS360 fix is ready to merge; no actionable current-head risk remains.

Architecture risk: Low · up to 82780

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/functions/src/date.rs: Under the US method, days360_core now changes the ending day to 30 when both dates are the last day of February; previously, it left the ending day unchanged at this point.
  • observed — Modified behavior in crates/functions/src/date.rs: The DAYS360 test suite now checks that the interval from February 28, 2021 to that same date returns zero.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the fix to the US DAYS360 method for dates that are both the last day of February.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@echelon

echelon commented Oct 24, 2026

Copy link
Copy Markdown
Member

Thanks for the fix! DAYS360's US method is an area where Excel is known to differ from the NASD rule, and the PR notes it wasn't checked against Excel. I'm holding it until we can confirm Excel's results for a few end-of-February pairs (for example 2/28/2021→2/28/2021 and 2/28/2011→2/29/2012).

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving at 8278063. I read the whole diff: when both dates are the last day of February the US method now sets the end day to 30, as the NASD rule has it (the start day was already moved to 30), and the new test checks 28 Feb 2021 to 28 Feb 2021 gives 0. The gate job (Ubuntu) and SonarCloud Scan pass at this head.

@Harrison-Booth

Copy link
Copy Markdown
Contributor

I checked these formulas in a new, unsaved Excel workbook through Windows PowerShell COM (each formula entered into a cell and calculated):

Formula Excel result
=DAYS360(DATE(2021,2,28),DATE(2022,2,28)) 358
=DAYS360(DATE(2020,2,29),DATE(2021,2,28)) 358
=DAYS360(DATE(2022,2,28),DATE(2021,2,28)) -362
=DAYS360(DATE(2021,2,28),DATE(2021,3,31)) 30

The proposed adjustment that maps the end date to day 30 when both dates are February month-end would change the first two observed results from 358 to 360. The reversed-order result is -362, and the March-end control is 30.

@Silvertree2010

Copy link
Copy Markdown
Contributor Author

Closing to cut down the review queue during the craft-libs refactor. I'll redo this on the new main if it's still relevant.

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.

4 participants