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

Unexpected value for negative durations #1700

Open
methodus opened this issue Nov 16, 2021 · 0 comments
Open

Unexpected value for negative durations #1700

methodus opened this issue Nov 16, 2021 · 0 comments

Comments

@methodus
Copy link

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

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