[Bug]: DAYS360 (US method) ignores the end-of-month rule when the start date is the last day of February

Open Beginner friendly
#1,879 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
backend, data

Research direction

Start with DateTimeHelper.ts, especially toBasisUS, where the issue identifies the order of the February and end-of-month checks. Run the provided three DAYS360 examples and compare their results with the expected values. Done means the first two return 300 and 30 while the third still returns 60.

Written by the indexing model from the issue text.

Description

Description

With the default US (NASD) method, when the start date is the last day of February it becomes the 30th, and then an end date on the 31st also becomes the 30th (Excel DAYS360 documentation). HyperFormula applies the February adjustment after the start.day === 30 && end.day === 31 check, so the end date is not adjusted and the result is one day too large.

const { HyperFormula } = require('hyperformula')

const hf = HyperFormula.buildFromArray([[
  '=DAYS360(DATE(2024,2,29), DATE(2024,12,31))',
  '=DAYS360(DATE(2023,2,28), DATE(2023,3,31))',
  '=DAYS360(DATE(2024,1,30), DATE(2024,3,31))',
]], { licenseKey: 'gpl-v3' })

console.log(hf.getSheetValues(0)[0])

Actual: [ 301, 31, 60 ]

Expected (Excel, LibreOffice): [ 300, 30, 60 ]

The third call (start already on the 30th) returns 60, which shows the end-of-month rule works when the start date did not need the February adjustment.

Cause: DateTimeHelper.toBasisUS in DateTimeHelper.ts checks start.day === 30 && end.day === 31 before setting start.day = 30 for the last day of February.

Video or screenshots

N/A

Demo

https://gist.github.com/trackoor/956d3d7fa69b41acdf9f9bd48071b52e

HyperFormula version

3.5.0 (npm), also master (187dfa16) and develop (5a6eb09)

Your framework

None (Node.js)

Your environment

Node.js v26.13.0 on Linux

Credit: https://ucsbplse.github.io/

Dominant language
TypeScript
Stars
2.8k
Forks
175
Avg merge
2d 7h
Merged PRs (30d)
22

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from handsontable/hyperformula

All issues in handsontable/hyperformula

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.