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

fix: duration plugin getter get result 0 instead of undefined #2369

Merged
merged 3 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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