Skip to content

Commit

Permalink
fix: fix utc plugin diff bug in DST (#1171)
Browse files Browse the repository at this point in the history
fix #1097, fix #1021
  • Loading branch information
iamkun authored Oct 27, 2020
1 parent a6e68f6 commit 990012b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plugin/utc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export default (option, Dayjs, dayjs) => {
}
const oldDiff = proto.diff
proto.diff = function (input, units, float) {
if (this.$u === input.$u) {
return oldDiff.call(this, input, units, float)
}
const localThis = this.local()
const localInput = dayjs(input).local()
return oldDiff.call(localThis, localInput, units, float)
Expand Down
8 changes: 8 additions & 0 deletions test/timezone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ it('UTC and utcOffset', () => {
expect(moment.utc(test2).utcOffset(-60).format())
.toBe(dayjs.utc(test2).utcOffset(-60).format())
})

it('UTC diff in DST', () => {
// DST till 2020-10-25
const day1 = dayjs.utc('20201023') // in DST
const day2 = dayjs.utc('20201026')
expect(day1.diff(day2, 'd'))
.toBe(-3)
})

0 comments on commit 990012b

Please sign in to comment.