Skip to content

Commit f8da3fe

Browse files
committed
fix: fix utc plugin diff bug in DST (#1171)
fix #1097, fix #1021
1 parent 9e8f8d9 commit f8da3fe

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/plugin/utc/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export default (option, Dayjs, dayjs) => {
112112
}
113113
const oldDiff = proto.diff
114114
proto.diff = function (input, units, float) {
115+
if (this.$u === input.$u) {
116+
return oldDiff.call(this, input, units, float)
117+
}
115118
const localThis = this.local()
116119
const localInput = dayjs(input).local()
117120
return oldDiff.call(localThis, localInput, units, float)

test/timezone.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ it('UTC and utcOffset', () => {
6262
expect(moment.utc(test2).utcOffset(-60).format())
6363
.toBe(dayjs.utc(test2).utcOffset(-60).format())
6464
})
65+
66+
it('UTC diff in DST', () => {
67+
// DST till 2020-10-25
68+
const day1 = dayjs.utc('20201023') // in DST
69+
const day2 = dayjs.utc('20201026')
70+
expect(day1.diff(day2, 'd'))
71+
.toBe(-3)
72+
})

0 commit comments

Comments
 (0)