Skip to content

Commit

Permalink
fix: update Duration plugin to support no-argument (#1400)
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusTheHun committed Mar 8, 2021
1 parent 319f616 commit 8d9a5ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/plugin/duration/index.js
Expand Up @@ -61,6 +61,10 @@ class Duration {
constructor(input, unit, locale) {
this.$d = {}
this.$l = locale
if (input === undefined) {
this.$ms = 0
this.parseFromMilliseconds()
}
if (unit) {
return wrapper(input * unitToMS[prettyUnit(unit)], this)
}
Expand Down
4 changes: 4 additions & 0 deletions test/plugin/duration.test.js
Expand Up @@ -17,6 +17,10 @@ afterEach(() => {
})

describe('Creating', () => {
it('no argument', () => {
expect(dayjs.duration().toISOString()).toBe('P0D')
expect(dayjs.duration().asMilliseconds()).toBe(0)
})
it('milliseconds', () => {
expect(dayjs.duration(1, 'ms').toISOString()).toBe('PT0.001S')
expect(dayjs.duration(100).toISOString()).toBe('PT0.1S')
Expand Down

0 comments on commit 8d9a5ae

Please sign in to comment.