import addHours from '../addHours/index' ; import toDate from '../toDate/index' ; import requiredArgs from '../_lib/requiredArgs/index' ; import type { Interval , StepOptions } from '../types' ; name category summary description param { Interval } interval - the interval. See [Interval] https param options param { Number } options . step returns { Date [ ] } throws throws throws throws example export default function eachHourOfInterval ( dirtyInterval , options ? ) { requiredArgs ( 1 , arguments ) ; const interval = dirtyInterval || { } ; const startDate = toDate ( interval . start ) ; const endDate = toDate ( interval . end ) ; const startTime = startDate . getTime ( ) ; const endTime = endDate . getTime ( ) ; if ( ! ( startTime <= endTime ) ) { throw new RangeError ( 'Invalid interval' ) ; } const dates = [ ] ; let currentDate = startDate ; currentDate . setMinutes ( 0 , 0 , 0 ) ; const step = options && 'step' in options ? Number ( options . step ) : 1 ; if ( step < 1 || isNaN ( step ) ) throw new RangeError ( '`options.step` must be a number greater than 1' ) ; while ( currentDate . getTime ( ) <= endTime ) { dates . push ( toDate ( currentDate ) ) ; currentDate = addHours ( currentDate , step ) ; } return dates ; }