1 | import { toDate } from "./toDate.mjs";
|
2 |
|
3 | /**
|
4 | * @name isSameYear
|
5 | * @category Year Helpers
|
6 | * @summary Are the given dates in the same year?
|
7 | *
|
8 | * @description
|
9 | * Are the given dates in the same year?
|
10 | *
|
11 | * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
12 | *
|
13 | * @param dateLeft - The first date to check
|
14 | * @param dateRight - The second date to check
|
15 | *
|
16 | * @returns The dates are in the same year
|
17 | *
|
18 | * @example
|
19 | * // Are 2 September 2014 and 25 September 2014 in the same year?
|
20 | * const result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25))
|
21 | * //=> true
|
22 | */
|
23 | export function isSameYear(dateLeft, dateRight) {
|
24 | const _dateLeft = toDate(dateLeft);
|
25 | const _dateRight = toDate(dateRight);
|
26 | return _dateLeft.getFullYear() === _dateRight.getFullYear();
|
27 | }
|
28 |
|
29 | // Fallback for modularized imports:
|
30 | export default isSameYear;
|