Skip to content

Commit 89ddb3b

Browse files
pvmeijelohsory1324
authored andcommitted
fix: Added .valueOf method to Duration class (iamkun#2226)
1 parent e5750a1 commit 89ddb3b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/plugin/duration/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ class Duration {
235235
.fromNow(!withSuffix)
236236
}
237237

238+
valueOf() {
239+
return this.asMilliseconds()
240+
}
241+
238242
milliseconds() { return this.get('milliseconds') }
239243
asMilliseconds() { return this.as('milliseconds') }
240244
seconds() { return this.get('seconds') }

test/plugin/duration.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ describe('Creating', () => {
6767
ms: -1
6868
}).toISOString()).toBe('-PT0.001S')
6969
})
70+
it('convert to milliseconds', () => {
71+
expect(+dayjs.duration(100)).toBe(100)
72+
})
7073
})
7174

7275
describe('Parse ISO string', () => {

0 commit comments

Comments
 (0)