import moment from 'moment-timezone' ; import { TickFormatter , TickFormatterOptions } from '../../chart_types/xy_chart/utils/specs' ; import { getMomentWithTz } from './date_time' ; public export function timeFormatter ( format ) { return ( value , options ? ) : string => getMomentWithTz ( value , options && options . timeZone ) . format ( format ) ; } public export function niceTimeFormatter ( domain ) { const minDate = moment ( domain [ 0 ] ) ; const maxDate = moment ( domain [ 1 ] ) ; const diff = maxDate . diff ( minDate , 'days' ) ; const format = niceTimeFormatByDay ( diff ) ; return timeFormatter ( format ) ; } public export function niceTimeFormatByDay ( days ) { if ( days > 30 ) return 'YYYY-MM-DD' ; if ( days > 7 ) return 'MMMM DD' ; if ( days > 1 ) return 'MM-DD HH:mm' ; return 'HH:mm:ss' ; }