Skip to content

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

Open

Description

@trackoor

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/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions