negative ISO8601 duration strings are not handled properly by the duration function
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
negative ISO8601 duration strings are not handled properly.
```
const durationString = dayjs.duration(-1000).toISOString(); //Results in -PT1S
expect(durationString).toEqual('-PT1S');
const actual = dayjs.duration(durationString);
expect(actual.asSeconds()).toEqual(-1); // this fails !!! results in +1
```
**Expected behavior**
Solution 1
toISOString should apply negative sign to the numeric portions of the string ( for the above eg it should return PT-1S)
Solution 2
duration should handle leading negative sign as a negative duration. ( for the above example asSeconds should return -1)
**Relates to**
https://github.com/iamkun/dayjs/issues/1700
**Information**
- Day.js Version [e.g. v1.10.7]
- OS: node/ubuntu
Contributor guide
Research direction
No source file or test is named. Start by locating the duration parsing and toISOString entry points, then reproduce the provided -PT1S example; done means negative ISO8601 durations round-trip with asSeconds() returning -1 and regression coverage records the chosen behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100