index.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import toDate from "../toDate/index.js";
  2. import endOfDay from "../endOfDay/index.js";
  3. import endOfMonth from "../endOfMonth/index.js";
  4. import requiredArgs from "../_lib/requiredArgs/index.js";
  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. * ### v2.0.0 breaking changes:
  14. *
  15. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  16. *
  17. * @param {Date|Number} date - the date to check
  18. * @returns {Boolean} the date is the last day of a month
  19. * @throws {TypeError} 1 argument required
  20. *
  21. * @example
  22. * // Is 28 February 2014 the last day of a month?
  23. * var result = isLastDayOfMonth(new Date(2014, 1, 28))
  24. * //=> true
  25. */
  26. export default function isLastDayOfMonth(dirtyDate) {
  27. requiredArgs(1, arguments);
  28. var date = toDate(dirtyDate);
  29. return endOfDay(date).getTime() === endOfMonth(date).getTime();
  30. }