File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed
Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ class Duration {
139139
140140 let seconds = this . $d . seconds || 0
141141 if ( this . $d . milliseconds ) {
142- seconds += this . $d . milliseconds / 1000
142+ seconds += Math . round ( this . $d . milliseconds ) / 1000
143143 }
144144
145145 const S = getNumberUnitFormat ( seconds , 'S' )
Original file line number Diff line number Diff line change @@ -70,6 +70,13 @@ describe('Creating', () => {
7070 it ( 'convert to milliseconds' , ( ) => {
7171 expect ( + dayjs . duration ( 100 ) ) . toBe ( 100 )
7272 } )
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+ } )
7380} )
7481
7582describe ( 'Parse ISO string' , ( ) => {
You can’t perform that action at this time.
0 commit comments