startOfMonth.js 889 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. exports.startOfMonth = startOfMonth;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name startOfMonth
  6. * @category Month Helpers
  7. * @summary Return the start of a month for the given date.
  8. *
  9. * @description
  10. * Return the start of a month for the given date.
  11. * The result will be in the local timezone.
  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 original date
  16. *
  17. * @returns The start of a month
  18. *
  19. * @example
  20. * // The start of a month for 2 September 2014 11:55:00:
  21. * const result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0))
  22. * //=> Mon Sep 01 2014 00:00:00
  23. */
  24. function startOfMonth(date) {
  25. const _date = (0, _index.toDate)(date);
  26. _date.setDate(1);
  27. _date.setHours(0, 0, 0, 0);
  28. return _date;
  29. }