Skip to content

Commit

Permalink
fix: Added .valueOf method to Duration class (#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvmeijel authored Feb 11, 2023
1 parent e70bee7 commit 9b4fcfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/plugin/duration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ class Duration {
.fromNow(!withSuffix)
}

valueOf() {
return this.asMilliseconds()
}

milliseconds() { return this.get('milliseconds') }
asMilliseconds() { return this.as('milliseconds') }
seconds() { return this.get('seconds') }
Expand Down
3 changes: 3 additions & 0 deletions test/plugin/duration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ describe('Creating', () => {
ms: -1
}).toISOString()).toBe('-PT0.001S')
})
it('convert to milliseconds', () => {
expect(+dayjs.duration(100)).toBe(100)
})
})

describe('Parse ISO string', () => {
Expand Down

0 comments on commit 9b4fcfd

Please sign in to comment.