Repository navigation
Fix DAYS360 US method when both dates are last day of February - #2406
Silvertree2010 wants to merge 1 commit into
Conversation
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>
|
No actionable comments were generated in the recent review.
|
| 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:
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:
cratesArchitecture 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_corenow 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
DAYS360test suite now checks that the interval from February 28, 2021 to that same date returns zero.
-
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed -
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.
|
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
left a comment
There was a problem hiding this comment.
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.
|
I checked these formulas in a new, unsaved Excel workbook through Windows PowerShell COM (each formula entered into a cell and calculated):
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. |
|
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. |
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.rsfails without the fix (returns -2) and passes with it. Run withcargo test -p gridcraft-functions --lib date.Verified
date::tests::day_counts: fails onmainwithout the fix and passes with it (cargo test -p gridcraft-functions --lib day_counts).cargo xtask cipasses.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
DAYS360calculation 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.