index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = startOfMonth;
  6. var _index = _interopRequireDefault(require("../toDate/index.js"));
  7. var _index2 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /**
  10. * @name startOfMonth
  11. * @category Month Helpers
  12. * @summary Return the start of a month for the given date.
  13. *
  14. * @description
  15. * Return the start of a month for the given date.
  16. * The result will be in the local timezone.
  17. *
  18. * ### v2.0.0 breaking changes:
  19. *
  20. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  21. *
  22. * @param {Date|Number} date - the original date
  23. * @returns {Date} the start of a month
  24. * @throws {TypeError} 1 argument required
  25. *
  26. * @example
  27. * // The start of a month for 2 September 2014 11:55:00:
  28. * const result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0))
  29. * //=> Mon Sep 01 2014 00:00:00
  30. */
  31. function startOfMonth(dirtyDate) {
  32. (0, _index2.default)(1, arguments);
  33. var date = (0, _index.default)(dirtyDate);
  34. date.setDate(1);
  35. date.setHours(0, 0, 0, 0);
  36. return date;
  37. }
  38. module.exports = exports.default;