File tree 1 file changed +21
-21
lines changed
site/src/modules/workspaces/WorkspaceTiming/Chart
1 file changed +21
-21
lines changed Original file line number Diff line number Diff line change @@ -61,29 +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 ) ;
65
- const minutes = Math . floor ( seconds / 60 ) ;
66
- const hours = Math . floor ( minutes / 60 ) ;
67
- const days = Math . floor ( hours / 24 ) ;
64
+ const absTime = Math . abs ( time ) ;
65
+ let unit = "" ;
66
+ let value = 0 ;
68
67
69
- const parts : string [ ] = [ ] ;
70
- if ( days > 0 ) {
71
- parts . push ( `${ days } d` ) ;
68
+ if ( absTime < second ) {
69
+ value = time ;
70
+ unit = "ms" ;
71
+ } else if ( absTime < minute ) {
72
+ value = time / second ;
73
+ unit = "s" ;
74
+ } else if ( absTime < hour ) {
75
+ value = time / minute ;
76
+ unit = "m" ;
77
+ } else if ( absTime < day ) {
78
+ value = time / hour ;
79
+ unit = "h" ;
80
+ } else {
81
+ value = time / day ;
82
+ unit = "d" ;
72
83
}
73
- if ( hours > 0 ) {
74
- parts . push ( `${ hours % 24 } h` ) ;
75
- }
76
- if ( minutes > 0 ) {
77
- parts . push ( `${ minutes % 60 } m` ) ;
78
- }
79
- if ( seconds > 0 ) {
80
- parts . push ( `${ seconds % 60 } s` ) ;
81
- }
82
- if ( time % 1000 > 0 ) {
83
- parts . push ( `${ time % 1000 } ms` ) ;
84
- }
85
-
86
- return parts . join ( " " ) ;
84
+ return `${ value . toLocaleString ( undefined , {
85
+ maximumFractionDigits : 2 ,
86
+ } ) } ${ unit } `;
87
87
} ;
88
88
89
89
export const calcOffset = ( range : TimeRange , baseRange : TimeRange ) : number => {
You can’t perform that action at this time.
0 commit comments