Skip to content

Commit

Permalink
fix: duration plugin getter get result 0 instead of undefined (iamkun…
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun authored Jul 15, 2023
1 parent f0a0b54 commit 061aa7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugin/duration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Duration {
} else {
base = this.$d[pUnit]
}
return base === 0 ? 0 : base // a === 0 will be true on both 0 and -0
return base || 0 // a === 0 will be true on both 0 and -0
}

add(input, unit, isSubtract) {
Expand Down
6 changes: 6 additions & 0 deletions test/plugin/duration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ describe('Add', () => {
expect(a.add({ days: 5 }).days()).toBe(6)
})

describe('Add to a dayjs()', () => {
const a = dayjs()
const b = dayjs.duration({ hours: 7, minutes: 10 })
expect(a.add(b)).toEqual(a.add(7, 'hours').add(10, 'minutes'))
})

test('Add duration', () => {
const a = dayjs('2020-10-01')
const days = dayjs.duration(2, 'days')
Expand Down

0 comments on commit 061aa7e

Please sign in to comment.