isLastDayOfMonth.mjs 913 B

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