getYearsUntil()function
getYearsUntil(target: PossibleDate, current?: PossibleDate, caller: AnyCaller = getYearsUntil): number
| Param | Type | |
|---|---|---|
target | PossibleDate | Date to count up to. required |
current | PossibleDate | Date to count from (defaults to now). |
caller | AnyCaller | Function to attribute a thrown error to (defaults to getYearsUntil itself). Defaults to getYearsUntil |
| Return | |
|---|---|
number | Number of calendar years from current to target (negative if target is in the past). |
| Throws | |
|---|---|
RequiredError | If target or current cannot be converted to a valid date. |
Count the calendar years until a date.
- e.g. from December 31st to January 1st is 1 year, even though it's only 1 day.
Examples
getYearsUntil(target) // 2