index.js 678 B

1234567891011121314151617181920212223242526
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Month Helpers
  4. * @summary Return the start of a month for the given date.
  5. *
  6. * @description
  7. * Return the start of a month for the given date.
  8. * The result will be in the local timezone.
  9. *
  10. * @param {Date|String|Number} date - the original date
  11. * @returns {Date} the start of a month
  12. *
  13. * @example
  14. * // The start of a month for 2 September 2014 11:55:00:
  15. * var result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0))
  16. * //=> Mon Sep 01 2014 00:00:00
  17. */
  18. function startOfMonth (dirtyDate) {
  19. var date = parse(dirtyDate)
  20. date.setDate(1)
  21. date.setHours(0, 0, 0, 0)
  22. return date
  23. }
  24. module.exports = startOfMonth