File tree 2 files changed +8
-1
lines changed
2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ class Duration {
139
139
140
140
let seconds = this . $d . seconds || 0
141
141
if ( this . $d . milliseconds ) {
142
- seconds += this . $d . milliseconds / 1000
142
+ seconds += Math . round ( this . $d . milliseconds ) / 1000
143
143
}
144
144
145
145
const S = getNumberUnitFormat ( seconds , 'S' )
Original file line number Diff line number Diff line change @@ -70,6 +70,13 @@ describe('Creating', () => {
70
70
it ( 'convert to milliseconds' , ( ) => {
71
71
expect ( + dayjs . duration ( 100 ) ) . toBe ( 100 )
72
72
} )
73
+ it ( 'handles rounding to millisecond precision' , ( ) => {
74
+ expect ( dayjs . duration ( 2 / 3 ) . toISOString ( ) ) . toBe ( 'PT0.001S' )
75
+ } )
76
+ it ( 'should handle round with millisecond precision when negative' , ( ) => {
77
+ expect ( dayjs . duration ( 1000.5 ) . toISOString ( ) ) . toBe ( 'PT1.001S' )
78
+ expect ( dayjs . duration ( - 1000.5 ) . toISOString ( ) ) . toBe ( '-PT1S' )
79
+ } )
73
80
} )
74
81
75
82
describe ( 'Parse ISO string' , ( ) => {
You can’t perform that action at this time.
0 commit comments