Skip to content

Commit 061aa7e

Browse files
authored
fix: duration plugin getter get result 0 instead of undefined (iamkun#2369)
1 parent f0a0b54 commit 061aa7e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/plugin/duration/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class Duration {
198198
} else {
199199
base = this.$d[pUnit]
200200
}
201-
return base === 0 ? 0 : base // a === 0 will be true on both 0 and -0
201+
return base || 0 // a === 0 will be true on both 0 and -0
202202
}
203203

204204
add(input, unit, isSubtract) {

test/plugin/duration.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ describe('Add', () => {
186186
expect(a.add({ days: 5 }).days()).toBe(6)
187187
})
188188

189+
describe('Add to a dayjs()', () => {
190+
const a = dayjs()
191+
const b = dayjs.duration({ hours: 7, minutes: 10 })
192+
expect(a.add(b)).toEqual(a.add(7, 'hours').add(10, 'minutes'))
193+
})
194+
189195
test('Add duration', () => {
190196
const a = dayjs('2020-10-01')
191197
const days = dayjs.duration(2, 'days')

0 commit comments

Comments
 (0)