Unexpected value for negative durations
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
`
const d = dayjs.duration(-61001)
console.log(d) // prints: l{$d: Object{years: 0, months: 0, days: 0, hours: 0, minutes: -1, seconds: -1, milliseconds: -1}, $l: 'en', $ms: -61001}
`
**Expected behavior**
The negative sign should bubble up to the highest unit. It should return then:
`
l{$d: Object{years: 0, months: 0, days: 0, hours: 0, minutes: -1, seconds: 1, milliseconds: 1}, $l: 'en', $ms: -61001}
`
because:
_-1 * 60 * 1000 + 1 * 1000 + 1 = -61000_
Especially, when formatting a negative value, you will get something like "-01:-01:-1" where "-01:01:1" was expected.
**Information**
- Day.js Version [e.g. v1.10.6]
- OS: [e.g. Chrome Windows]
- Browser [e.g. chrome 62]
This issue is related to #1317 but seems to only partially solve this
Contributor guide
Research direction
The report names no files, tests, or entry points. Reproduce the issue with dayjs.duration(-61001), then locate the duration normalization and formatting paths; done means negative values preserve the sign only on the highest unit and format as "-01:01:1" rather than repeating negative signs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100