import addDays from '../addDays/index' ; import differenceInCalendarDays from '../differenceInCalendarDays/index' ; import isSameDay from '../isSameDay/index' ; import isValid from '../isValid/index' ; import isWeekend from '../isWeekend/index' ; import toDate from '../toDate/index' ; import requiredArgs from '../_lib/requiredArgs/index' ; import toInteger from '../_lib/toInteger/index' ; name category summary description param { Date | Number } dateLeft param { Date | Number } dateRight returns { Number } throws example export default function differenceInBusinessDays ( dirtyDateLeft , dirtyDateRight ) { requiredArgs ( 2 , arguments ) ; const dateLeft = toDate ( dirtyDateLeft ) ; let dateRight = toDate ( dirtyDateRight ) ; if ( ! isValid ( dateLeft ) || ! isValid ( dateRight ) ) return NaN ; const calendarDifference = differenceInCalendarDays ( dateLeft , dateRight ) ; const sign = calendarDifference < 0 ? - 1 : 1 ; const weeks = toInteger ( calendarDifference / 7 ) ; let result = weeks * 5 ; dateRight = addDays ( dateRight , weeks * 7 ) ; while ( ! isSameDay ( dateLeft , dateRight ) ) { result += isWeekend ( dateRight ) ? 0 : sign ; dateRight = addDays ( dateRight , sign ) ; } return result === 0 ? 0 : result ; }