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 eachYearOfInterval ( dirtyInterval ) { requiredArgs ( 1 , arguments ) ; const interval = dirtyInterval || { } ; const startDate = toDate ( interval . start ) ; const endDate = toDate ( interval . end ) ; const endTime = endDate . getTime ( ) ; if ( ! ( startDate . getTime ( ) <= endTime ) ) { throw new RangeError ( 'Invalid interval' ) ; } const dates = [ ] ; const currentDate = startDate ; currentDate . setHours ( 0 , 0 , 0 , 0 ) ; currentDate . setMonth ( 0 , 1 ) ; while ( currentDate . getTime ( ) <= endTime ) { dates . push ( toDate ( currentDate ) ) ; currentDate . setFullYear ( currentDate . getFullYear ( ) + 1 ) ; } return dates ; }