import { GTE_INTERVAL_RE } from './interval_regexp' ; import { parseInterval , TimeRangeBounds } from '../../../data/common' ; import { ValidateIntervalError } from './errors' ; export function validateInterval ( bounds , interval , maxBuckets ) { const { min , max } = bounds ; if ( ! interval ) return ; if ( interval === 'auto' ) return ; const greaterThanMatch = interval . match ( GTE_INTERVAL_RE ) ; if ( greaterThanMatch ) return ; const duration = parseInterval ( interval ) ; if ( duration ) { const span = max ! . valueOf ( ) - min ! . valueOf ( ) ; const buckets = Math . floor ( span / duration . asMilliseconds ( ) ) ; if ( buckets > maxBuckets ) { throw new ValidateIntervalError ( ) ; } } }