1 | ;
|
2 | exports.isSameMonth = isSameMonth;
|
3 | var _index = require("./toDate.js");
|
4 |
|
5 | /**
|
6 | * @name isSameMonth
|
7 | * @category Month Helpers
|
8 | * @summary Are the given dates in the same month (and year)?
|
9 | *
|
10 | * @description
|
11 | * Are the given dates in the same month (and year)?
|
12 | *
|
13 | * @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).
|
14 | *
|
15 | * @param dateLeft - The first date to check
|
16 | * @param dateRight - The second date to check
|
17 | *
|
18 | * @returns The dates are in the same month (and year)
|
19 | *
|
20 | * @example
|
21 | * // Are 2 September 2014 and 25 September 2014 in the same month?
|
22 | * const result = isSameMonth(new Date(2014, 8, 2), new Date(2014, 8, 25))
|
23 | * //=> true
|
24 | *
|
25 | * @example
|
26 | * // Are 2 September 2014 and 25 September 2015 in the same month?
|
27 | * const result = isSameMonth(new Date(2014, 8, 2), new Date(2015, 8, 25))
|
28 | * //=> false
|
29 | */
|
30 | function isSameMonth(dateLeft, dateRight) {
|
31 | const _dateLeft = (0, _index.toDate)(dateLeft);
|
32 | const _dateRight = (0, _index.toDate)(dateRight);
|
33 | return (
|
34 | _dateLeft.getFullYear() === _dateRight.getFullYear() &&
|
35 | _dateLeft.getMonth() === _dateRight.getMonth()
|
36 | );
|
37 | }
|