-
-
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
Added deltaZone in the equation when calculating diff and added utcOffset api method #453
Conversation
Cool |
@@ -303,18 +302,23 @@ class Dayjs { | |||
}) | |||
} | |||
|
|||
utcOffset() { | |||
return -Math.round(this.$d.getTimezoneOffset() / 15) * 15 |
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.
why 15
here, can this be any other 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.
In the momentjs
code, there is this comment
// On Firefox.24 Date#getTimezoneOffset returns a floating point.
// moment/moment#1871
It seems there was a bug with FF24, and in order to avoid issues with the floating point, they round it around 15, which are minutes.
I'm not fully sure about how this solves a possible bug, but momentjs
is fully tested, and I think we can trust its code. Maybe we should add some sort of comment?
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.
I see, thanks. And add some comments please.
Codecov Report
@@ Coverage Diff @@
## dev #453 +/- ##
===================================
Coverage 100% 100%
===================================
Files 55 55
Lines 484 486 +2
Branches 75 75
===================================
+ Hits 484 486 +2
Continue to review full report at Codecov.
|
[C.W]: diff / C.MILLISECONDS_A_WEEK, | ||
[C.D]: diff / C.MILLISECONDS_A_DAY, | ||
[C.W]: (diff - zoneDelta) / C.MILLISECONDS_A_WEEK, | ||
[C.D]: (diff - zoneDelta) / C.MILLISECONDS_A_DAY, |
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.
Why we just need zoneDelta only in week and day?
Could this change added to diff
in line 315?
const diff = this - that - zoneDelta
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.
I'm not sure 😅 but substracting the zoneDelta to other units than week
and day
, makes the tests broke.
Maybe because units under day
do not consider daysaving?
## [1.8.2](v1.8.1...v1.8.2) (2019-02-02) ### Bug Fixes * Add missing czech language locale ([#461](#461)) ([7e04004](7e04004)) * add deltaZone in the equation when calculating diff and added utcOffset api method ([#453](#453)) ([ce2e30e](ce2e30e)) * fix it locale error ([#458](#458)) ([f6d9a64](f6d9a64))
🎉 This PR is included in version 1.8.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [1.8.2](iamkun/dayjs@v1.8.1...v1.8.2) (2019-02-02) ### Bug Fixes * Add missing czech language locale ([#461](iamkun/dayjs#461)) ([7e04004](iamkun/dayjs@7e04004)) * add deltaZone in the equation when calculating diff and added utcOffset api method ([#453](iamkun/dayjs#453)) ([ce2e30e](iamkun/dayjs@ce2e30e)) * fix it locale error ([#458](iamkun/dayjs#458)) ([f6d9a64](iamkun/dayjs@f6d9a64))
## [1.8.2](iamkun/dayjs@v1.8.1...v1.8.2) (2019-02-02) ### Bug Fixes * Add missing czech language locale ([#461](iamkun/dayjs#461)) ([7e04004](iamkun/dayjs@7e04004)) * add deltaZone in the equation when calculating diff and added utcOffset api method ([#453](iamkun/dayjs#453)) ([ce2e30e](iamkun/dayjs@ce2e30e)) * fix it locale error ([#458](iamkun/dayjs#458)) ([f6d9a64](iamkun/dayjs@f6d9a64))
## [1.8.2](iamkun/dayjs@v1.8.1...v1.8.2) (2019-02-02) ### Bug Fixes * Add missing czech language locale ([#461](iamkun/dayjs#461)) ([7e04004](iamkun/dayjs@7e04004)) * add deltaZone in the equation when calculating diff and added utcOffset api method ([#453](iamkun/dayjs#453)) ([ce2e30e](iamkun/dayjs@ce2e30e)) * fix it locale error ([#458](iamkun/dayjs#458)) ([f6d9a64](iamkun/dayjs@f6d9a64))
I've looked into momentjs code, and tried to understand why method dayjs().diff() was returning different values than moment().diff() when the unit was day. Happens that momentjs uses the offset of each element to calculate hour zone difference, and adds it to the equation.
I've had to add the utcOffset() method in the core (where the diff() method is), but only the get version.
This should resolve #384
As mentioned at #452 I've added test and documentation for
utcOffset
method