import toDate from '../toDate/index' ; import differenceInCalendarDays from '../differenceInCalendarDays/index' ; import requiredArgs from '../_lib/requiredArgs/index' ; function compareLocalAsc ( dateLeft , dateRight ) { const diff = dateLeft . getFullYear ( ) - dateRight . getFullYear ( ) || dateLeft . getMonth ( ) - dateRight . getMonth ( ) || dateLeft . getDate ( ) - dateRight . getDate ( ) || dateLeft . getHours ( ) - dateRight . getHours ( ) || dateLeft . getMinutes ( ) - dateRight . getMinutes ( ) || dateLeft . getSeconds ( ) - dateRight . getSeconds ( ) || dateLeft . getMilliseconds ( ) - dateRight . getMilliseconds ( ) ; if ( diff < 0 ) { return - 1 ; } else if ( diff > 0 ) { return 1 ; } else { return diff ; } } name category summary description param { Date | Number } dateLeft param { Date | Number } dateRight returns { Number } throws example export default function differenceInDays ( dirtyDateLeft , dirtyDateRight ) { requiredArgs ( 2 , arguments ) ; const dateLeft = toDate ( dirtyDateLeft ) ; const dateRight = toDate ( dirtyDateRight ) ; const sign = compareLocalAsc ( dateLeft , dateRight ) ; const difference = Math . abs ( differenceInCalendarDays ( dateLeft , dateRight ) ) ; dateLeft . setDate ( dateLeft . getDate ( ) - sign * difference ) ; const isLastDayNotFull = Number ( compareLocalAsc ( dateLeft , dateRight ) === - sign ) ; const result = sign * ( difference - isLastDayNotFull ) ; return result === 0 ? 0 : result ; }