import moment , { Moment } from 'moment' ; import { round } from 'lodash' ; import { TimeData } from './interface' ; export type TimeRangeInput = ( string | Moment ) [ ] ; param dates example export function processQueryTimeRange ( times = [ ] ) { if ( times . length !== 2 ) return [ ] ; return times . map ( ( item , index ) => { if ( ! moment . isMoment ( item ) ) { item = moment ( item ) ; } if ( index === 0 ) { return item . startOf ( 'day' ) . valueOf ( ) ; } else { return item . endOf ( 'day' ) . valueOf ( ) ; } } ) ; } param val export function transformDayToTimeRange ( val ) { const beginTime = moment ( ) . subtract ( val - 1 , 'days' ) ; return [ beginTime , moment ( ) ] ; } param val export function transformTimeRangeToDay ( val ) { return round ( ( val . endTime - val . startTime ) / ( 1000 * 24 * 60 * 60 ) , 0 ) ; }