import toDate from '../toDate/index' ; import differenceInCalendarYears from '../differenceInCalendarYears/index' ; import compareAsc from '../compareAsc/index' ; import requiredArgs from '../_lib/requiredArgs/index' ; name category summary description param { Date | Number } dateLeft param { Date | Number } dateRight returns { Number } throws example export default function differenceInYears ( dirtyDateLeft , dirtyDateRight ) { requiredArgs ( 2 , arguments ) ; const dateLeft = toDate ( dirtyDateLeft ) ; const dateRight = toDate ( dirtyDateRight ) ; const sign = compareAsc ( dateLeft , dateRight ) ; const difference = Math . abs ( differenceInCalendarYears ( dateLeft , dateRight ) ) ; dateLeft . setFullYear ( 1584 ) ; dateRight . setFullYear ( 1584 ) ; const isLastYearNotFull = compareAsc ( dateLeft , dateRight ) === - sign ; const result = sign * ( difference - Number ( isLastYearNotFull ) ) ; return result === 0 ? 0 : result ; }