import addWeeks from '../addWeeks/index' ; import startOfWeek from '../startOfWeek/index' ; import toDate from '../toDate/index' ; import type { Interval , LocaleOptions , WeekStartOptions } from '../types' ; import requiredArgs from '../_lib/requiredArgs/index' ; name category summary description param { Interval } interval - the interval. See [Interval] https param options param { Locale } options . locale - the locale object. See [Locale] https param { 0 | 1 | 2 | 3 | 4 | 5 | 6 } options . weekStartsOn returns { Date [ ] } throws throws throws throws example export default function eachWeekOfInterval ( dirtyInterval , options ? ) { 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 startDateWeek = startOfWeek ( startDate , options ) ; const endDateWeek = startOfWeek ( endDate , options ) ; startDateWeek . setHours ( 15 ) ; endDateWeek . setHours ( 15 ) ; endTime = endDateWeek . getTime ( ) ; const weeks = [ ] ; let currentWeek = startDateWeek ; while ( currentWeek . getTime ( ) <= endTime ) { currentWeek . setHours ( 0 ) ; weeks . push ( toDate ( currentWeek ) ) ; currentWeek = addWeeks ( currentWeek , 1 ) ; currentWeek . setHours ( 15 ) ; } return weeks ; }