-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix negative duration #1317
Fix negative duration #1317
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #1317 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 176 176
Lines 1709 1737 +28
Branches 391 394 +3
=========================================
+ Hits 1709 1737 +28
Continue to review full report at Codecov.
|
Cool, thanks |
## [1.10.4](v1.10.3...v1.10.4) (2021-01-22) ### Bug Fixes * Correct handling negative duration ([#1317](#1317)) ([3f5c085](3f5c085)) * Improve `Duration` types ([#1338](#1338)) ([4aca4b1](4aca4b1)) * parse a string for MMM month format with underscore delimiter ([#1349](#1349)) ([82ef9a3](82ef9a3)) * Update Bengali [bn] locale ([#1329](#1329)) ([02d96ec](02d96ec)) * update locale Portuguese [pt] yearStart ([#1345](#1345)) ([5c785d5](5c785d5)) * update Polish [pl] locale yearStart ([#1348](#1348)) ([e93e6b8](e93e6b8)) * Update Slovenian [sl] relativeTime locale ([#1333](#1333)) ([fe5f1d0](fe5f1d0))
🎉 This PR is included in version 1.10.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
src/plugin/duration/index.js
Outdated
@@ -25,6 +25,7 @@ const wrapper = (input, instance, unit) => | |||
new Duration(input, unit, instance.$l) // eslint-disable-line no-use-before-define | |||
|
|||
const prettyUnit = unit => `${$u.p(unit)}s` | |||
const roundNumber = number => number < 0 ? Math.ceil(number) : Math.floor(number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be replaced with Math.trunc(number)
, which is shorter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems not supported in IE :-(
## [1.10.4](iamkun/dayjs@v1.10.3...v1.10.4) (2021-01-22) ### Bug Fixes * Correct handling negative duration ([#1317](iamkun/dayjs#1317)) ([3f5c085](iamkun/dayjs@3f5c085)) * Improve `Duration` types ([#1338](iamkun/dayjs#1338)) ([4aca4b1](iamkun/dayjs@4aca4b1)) * parse a string for MMM month format with underscore delimiter ([#1349](iamkun/dayjs#1349)) ([82ef9a3](iamkun/dayjs@82ef9a3)) * Update Bengali [bn] locale ([#1329](iamkun/dayjs#1329)) ([02d96ec](iamkun/dayjs@02d96ec)) * update locale Portuguese [pt] yearStart ([#1345](iamkun/dayjs#1345)) ([5c785d5](iamkun/dayjs@5c785d5)) * update Polish [pl] locale yearStart ([#1348](iamkun/dayjs#1348)) ([e93e6b8](iamkun/dayjs@e93e6b8)) * Update Slovenian [sl] relativeTime locale ([#1333](iamkun/dayjs#1333)) ([fe5f1d0](iamkun/dayjs@fe5f1d0))
## [1.10.4](iamkun/dayjs@v1.10.3...v1.10.4) (2021-01-22) ### Bug Fixes * Correct handling negative duration ([#1317](iamkun/dayjs#1317)) ([3f5c085](iamkun/dayjs@3f5c085)) * Improve `Duration` types ([#1338](iamkun/dayjs#1338)) ([4aca4b1](iamkun/dayjs@4aca4b1)) * parse a string for MMM month format with underscore delimiter ([#1349](iamkun/dayjs#1349)) ([82ef9a3](iamkun/dayjs@82ef9a3)) * Update Bengali [bn] locale ([#1329](iamkun/dayjs#1329)) ([02d96ec](iamkun/dayjs@02d96ec)) * update locale Portuguese [pt] yearStart ([#1345](iamkun/dayjs#1345)) ([5c785d5](iamkun/dayjs@5c785d5)) * update Polish [pl] locale yearStart ([#1348](iamkun/dayjs#1348)) ([e93e6b8](iamkun/dayjs@e93e6b8)) * Update Slovenian [sl] relativeTime locale ([#1333](iamkun/dayjs#1333)) ([fe5f1d0](iamkun/dayjs@fe5f1d0))
## [1.10.4](iamkun/dayjs@v1.10.3...v1.10.4) (2021-01-22) ### Bug Fixes * Correct handling negative duration ([#1317](iamkun/dayjs#1317)) ([3f5c085](iamkun/dayjs@3f5c085)) * Improve `Duration` types ([#1338](iamkun/dayjs#1338)) ([4aca4b1](iamkun/dayjs@4aca4b1)) * parse a string for MMM month format with underscore delimiter ([#1349](iamkun/dayjs#1349)) ([82ef9a3](iamkun/dayjs@82ef9a3)) * Update Bengali [bn] locale ([#1329](iamkun/dayjs#1329)) ([02d96ec](iamkun/dayjs@02d96ec)) * update locale Portuguese [pt] yearStart ([#1345](iamkun/dayjs#1345)) ([5c785d5](iamkun/dayjs@5c785d5)) * update Polish [pl] locale yearStart ([#1348](iamkun/dayjs#1348)) ([e93e6b8](iamkun/dayjs@e93e6b8)) * Update Slovenian [sl] relativeTime locale ([#1333](iamkun/dayjs#1333)) ([fe5f1d0](iamkun/dayjs@fe5f1d0))
Problem
When I create Duration with negative number, the default value of each unit is -1 since you round everything down (Math.floor).
Solution
I add if case when number is negative it should run Math.ceil() instead.
Example
For positive number
For negative number (current)
For negative number (expected)