index.js 817 B

12345678910111213141516171819202122232425262728
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Quarter Helpers
  4. * @summary Return the last day of a year quarter for the given date.
  5. *
  6. * @description
  7. * Return the last day of a year quarter 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 last day of a quarter
  12. *
  13. * @example
  14. * // The last day of a quarter for 2 September 2014 11:55:00:
  15. * var result = lastDayOfQuarter(new Date(2014, 8, 2, 11, 55, 0))
  16. * //=> Tue Sep 30 2014 00:00:00
  17. */
  18. function lastDayOfQuarter (dirtyDate) {
  19. var date = parse(dirtyDate)
  20. var currentMonth = date.getMonth()
  21. var month = currentMonth - currentMonth % 3 + 3
  22. date.setMonth(month, 0)
  23. date.setHours(0, 0, 0, 0)
  24. return date
  25. }
  26. module.exports = lastDayOfQuarter