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

Added deltaZone in the equation when calculating diff and added utcOffset api method #453

Merged
merged 5 commits into from
Feb 2, 2019

Conversation

naulacambra
Copy link
Contributor

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

@iamkun
Copy link
Owner

iamkun commented Jan 16, 2019

Cool

@iamkun iamkun added the next release Will merge into next release label Jan 16, 2019
@@ -303,18 +302,23 @@ class Dayjs {
})
}

utcOffset() {
return -Math.round(this.$d.getTimezoneOffset() / 15) * 15
Copy link
Owner

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?

Copy link
Contributor Author

@naulacambra naulacambra Jan 16, 2019

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?

Copy link
Owner

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-io
Copy link

codecov-io commented Jan 16, 2019

Codecov Report

Merging #453 into dev will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@         Coverage Diff         @@
##            dev   #453   +/-   ##
===================================
  Coverage   100%   100%           
===================================
  Files        55     55           
  Lines       484    486    +2     
  Branches     75     75           
===================================
+ Hits        484    486    +2
Impacted Files Coverage Δ
src/constant.js 100% <ø> (ø) ⬆️
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3bd06f2...b56c77d. Read the comment docs.

[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,
Copy link
Owner

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

Copy link
Contributor Author

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?

@iamkun iamkun merged commit ce2e30e into iamkun:dev Feb 2, 2019
iamkun pushed a commit that referenced this pull request Feb 2, 2019
## [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))
@iamkun
Copy link
Owner

iamkun commented Feb 2, 2019

🎉 This PR is included in version 1.8.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@iamkun iamkun added the released label Feb 2, 2019
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this pull request May 10, 2022
## [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))
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this pull request May 10, 2022
## [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))
splashwizard pushed a commit to splashwizard/tracking-time that referenced this pull request Oct 21, 2024
## [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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next release Will merge into next release released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

diff() in "days" broken after making add() "days" aware of daylight-saving changes
3 participants