UNPKG

913 BJavaScriptView Raw
1import { endOfDay } from "./endOfDay.mjs";
2import { endOfMonth } from "./endOfMonth.mjs";
3import { toDate } from "./toDate.mjs";
4
5/**
6 * @name isLastDayOfMonth
7 * @category Month Helpers
8 * @summary Is the given date the last day of a month?
9 *
10 * @description
11 * Is the given date the last day of a month?
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 date - The date to check
16
17 * @returns The date is the last day of a month
18 *
19 * @example
20 * // Is 28 February 2014 the last day of a month?
21 * const result = isLastDayOfMonth(new Date(2014, 1, 28))
22 * //=> true
23 */
24export function isLastDayOfMonth(date) {
25 const _date = toDate(date);
26 return +endOfDay(_date) === +endOfMonth(_date);
27}
28
29// Fallback for modularized imports:
30export default isLastDayOfMonth;