isLastDayOfMonth.js 811 B

1234567891011121314151617181920212223242526272829
  1. import { endOfDay } from "./endOfDay.js";
  2. import { endOfMonth } from "./endOfMonth.js";
  3. import { toDate } from "./toDate.js";
  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. * @param date - The date to check
  13. * @param options - An object with options
  14. *
  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, options) {
  23. const _date = toDate(date, options?.in);
  24. return +endOfDay(_date, options) === +endOfMonth(_date, options);
  25. }
  26. // Fallback for modularized imports:
  27. export default isLastDayOfMonth;