import addQuarters from '../addQuarters/index' ; import startOfQuarter from '../startOfQuarter/index' ; import toDate from '../toDate/index' ; import type { Interval } from '../types' ; import requiredArgs from '../_lib/requiredArgs/index' ; name category summary description param { Interval } interval - the interval. See [Interval] https returns { Date [ ] } throws throws throws example export default function eachQuarterOfInterval ( dirtyInterval ) { requiredArgs ( 1 , arguments ) ; const interval = dirtyInterval || { } ; const startDate = toDate ( interval . start ) ; const endDate = toDate ( interval . end ) ; let endTime = endDate . getTime ( ) ; if ( ! ( startDate . getTime ( ) <= endTime ) ) { throw new RangeError ( 'Invalid interval' ) ; } const startDateQuarter = startOfQuarter ( startDate ) ; const endDateQuarter = startOfQuarter ( endDate ) ; endTime = endDateQuarter . getTime ( ) ; const quarters = [ ] ; let currentQuarter = startDateQuarter ; while ( currentQuarter . getTime ( ) <= endTime ) { quarters . push ( toDate ( currentQuarter ) ) ; currentQuarter = addQuarters ( currentQuarter , 1 ) ; } return quarters ; }