index.js 738 B

123456789101112131415161718192021222324252627
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Year Helpers
  4. * @summary Return the last day of a year for the given date.
  5. *
  6. * @description
  7. * Return the last day of a year 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 year
  12. *
  13. * @example
  14. * // The last day of a year for 2 September 2014 11:55:00:
  15. * var result = lastDayOfYear(new Date(2014, 8, 2, 11, 55, 00))
  16. * //=> Wed Dec 31 2014 00:00:00
  17. */
  18. function lastDayOfYear (dirtyDate) {
  19. var date = parse(dirtyDate)
  20. var year = date.getFullYear()
  21. date.setFullYear(year + 1, 0, 0)
  22. date.setHours(0, 0, 0, 0)
  23. return date
  24. }
  25. module.exports = lastDayOfYear