@@ -61,30 +61,29 @@ export const makeTicks = (time: number) => {
61
61
} ;
62
62
63
63
export const formatTime = ( time : number ) : string => {
64
- const seconds = Math . floor ( ( time / 1000 ) % 60 ) ;
65
- const minutes = Math . floor ( ( time / ( 1000 * 60 ) ) % 60 ) ;
66
- const hours = Math . floor ( ( time / ( 1000 * 60 * 60 ) ) % 24 ) ;
67
- const days = Math . floor ( time / ( 1000 * 60 * 60 * 24 ) ) ;
68
-
69
- const timeParts = [ ] ;
64
+ const seconds = Math . floor ( time / 1000 ) ;
65
+ const minutes = Math . floor ( seconds / 60 ) ;
66
+ const hours = Math . floor ( minutes / 60 ) ;
67
+ const days = Math . floor ( hours / 24 ) ;
70
68
69
+ const parts : string [ ] = [ ] ;
71
70
if ( days > 0 ) {
72
- timeParts . push ( `${ days } day ${ days > 1 ? "s" : "" } ` ) ;
71
+ parts . push ( `${ days } d ` ) ;
73
72
}
74
73
if ( hours > 0 ) {
75
- timeParts . push ( `${ hours } hour ${ hours > 1 ? "s" : "" } ` ) ;
74
+ parts . push ( `${ hours % 24 } h ` ) ;
76
75
}
77
76
if ( minutes > 0 ) {
78
- timeParts . push ( `${ minutes } minute ${ minutes > 1 ? "s" : "" } ` ) ;
77
+ parts . push ( `${ minutes % 60 } m ` ) ;
79
78
}
80
79
if ( seconds > 0 ) {
81
- timeParts . push ( `${ seconds } s` ) ;
80
+ parts . push ( `${ seconds % 60 } s` ) ;
82
81
}
83
- if ( time > 0 && time < 1000 ) {
84
- timeParts . push ( `${ time } ms` ) ;
82
+ if ( time % 1000 > 0 ) {
83
+ parts . push ( `${ time % 1000 } ms` ) ;
85
84
}
86
85
87
- return timeParts . join ( ", " ) ;
86
+ return parts . join ( " " ) ;
88
87
} ;
89
88
90
89
export const calcOffset = ( range : TimeRange , baseRange : TimeRange ) : number => {
0 commit comments