File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -342,8 +342,19 @@ export const prettyTime = (seconds: number): string => {
342342 return `${ format ( seconds . toFixed ( 1 ) ) } s` ;
343343 }
344344
345- const minutes = seconds / 60 ;
346- return `${ format ( minutes . toFixed ( 2 ) ) } m` ;
345+ const minutes = Math . floor ( seconds / 60 ) ;
346+ const minutesLabel = `${ format ( minutes . toFixed ( 0 ) ) } m` ;
347+ const remainingSeconds = seconds % 60 ;
348+
349+ if ( remainingSeconds === 0 ) {
350+ return minutesLabel ;
351+ }
352+
353+ const secondsLabel = `${ format (
354+ remainingSeconds . toFixed ( remainingSeconds % 1 === 0 ? 0 : 1 ) ,
355+ ) } s`;
356+
357+ return `${ minutesLabel } ${ secondsLabel } ` ;
347358} ;
348359
349360/**
Original file line number Diff line number Diff line change @@ -91,8 +91,10 @@ test('should pretty time correctly', () => {
9191 expect ( prettyTime ( 0.1234 ) ) . toEqual ( '0.12 s' ) ;
9292 expect ( prettyTime ( 1.234 ) ) . toEqual ( '1.23 s' ) ;
9393 expect ( prettyTime ( 12.34 ) ) . toEqual ( '12.3 s' ) ;
94- expect ( prettyTime ( 123.4 ) ) . toEqual ( '2.06 m' ) ;
95- expect ( prettyTime ( 1234 ) ) . toEqual ( '20.57 m' ) ;
94+ expect ( prettyTime ( 120 ) ) . toEqual ( '2 m' ) ;
95+ expect ( prettyTime ( 123.4 ) ) . toEqual ( '2 m 3.4 s' ) ;
96+ expect ( prettyTime ( 1234 ) ) . toEqual ( '20 m 34 s' ) ;
97+ expect ( prettyTime ( 1234.5 ) ) . toEqual ( '20 m 34.5 s' ) ;
9698} ) ;
9799
98100describe ( 'pick' , ( ) => {
You can’t perform that action at this time.
0 commit comments