@@ -9,6 +9,8 @@ import { i18n } from '@kbn/i18n';
99import { memoize } from 'lodash' ;
1010import { NOT_AVAILABLE_LABEL } from '../../common/i18n' ;
1111
12+ const HOURS_CUT_OFF = 3600000000 ; // 1 hour (in microseconds)
13+ const MINUTES_CUT_OFF = 60000000 ; // 1 minute (in microseconds)
1214const SECONDS_CUT_OFF = 10 * 1000000 ; // 10 seconds (in microseconds)
1315const MILLISECONDS_CUT_OFF = 10 * 1000 ; // 10 milliseconds (in microseconds)
1416const SPACE = ' ' ;
@@ -24,6 +26,38 @@ interface FormatterOptions {
2426 defaultValue ?: string ;
2527}
2628
29+ export function asHours (
30+ value : FormatterValue ,
31+ { withUnit = true , defaultValue = NOT_AVAILABLE_LABEL } : FormatterOptions = { }
32+ ) {
33+ if ( value == null ) {
34+ return defaultValue ;
35+ }
36+ const hoursLabel =
37+ SPACE +
38+ i18n . translate ( 'xpack.apm.formatters.hoursTimeUnitLabel' , {
39+ defaultMessage : 'h'
40+ } ) ;
41+ const formatted = asDecimal ( value / 3600000000 ) ;
42+ return `${ formatted } ${ withUnit ? hoursLabel : '' } ` ;
43+ }
44+
45+ export function asMinutes (
46+ value : FormatterValue ,
47+ { withUnit = true , defaultValue = NOT_AVAILABLE_LABEL } : FormatterOptions = { }
48+ ) {
49+ if ( value == null ) {
50+ return defaultValue ;
51+ }
52+ const minutesLabel =
53+ SPACE +
54+ i18n . translate ( 'xpack.apm.formatters.minutesTimeUnitLabel' , {
55+ defaultMessage : 'min'
56+ } ) ;
57+ const formatted = asDecimal ( value / 60000000 ) ;
58+ return `${ formatted } ${ withUnit ? minutesLabel : '' } ` ;
59+ }
60+
2761export function asSeconds (
2862 value : FormatterValue ,
2963 { withUnit = true , defaultValue = NOT_AVAILABLE_LABEL } : FormatterOptions = { }
@@ -81,6 +115,10 @@ type TimeFormatter = (
81115export const getTimeFormatter : TimeFormatter = memoize ( ( max : number ) => {
82116 const unit = timeUnit ( max ) ;
83117 switch ( unit ) {
118+ case 'h' :
119+ return asHours ;
120+ case 'm' :
121+ return asMinutes ;
84122 case 's' :
85123 return asSeconds ;
86124 case 'ms' :
@@ -91,7 +129,11 @@ export const getTimeFormatter: TimeFormatter = memoize((max: number) => {
91129} ) ;
92130
93131export function timeUnit ( max : number ) {
94- if ( max > SECONDS_CUT_OFF ) {
132+ if ( max > HOURS_CUT_OFF ) {
133+ return 'h' ;
134+ } else if ( max > MINUTES_CUT_OFF ) {
135+ return 'm' ;
136+ } else if ( max > SECONDS_CUT_OFF ) {
95137 return 's' ;
96138 } else if ( max > MILLISECONDS_CUT_OFF ) {
97139 return 'ms' ;
0 commit comments