Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

negative ISO8601 duration strings are not handled properly by the duration function #1788

Open
kaujaj opened this issue Feb 1, 2022 · 0 comments

Comments

@kaujaj
Copy link

kaujaj commented Feb 1, 2022

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
#1700

Information

  • Day.js Version [e.g. v1.10.7]
  • OS: node/ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant