index.js 930 B

1234567891011121314151617181920212223242526272829
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name endOfQuarter
  5. * @category Quarter Helpers
  6. * @summary Return the end of a year quarter for the given date.
  7. *
  8. * @description
  9. * Return the end of a year quarter for the given date.
  10. * The result will be in the local timezone.
  11. *
  12. * @param {Date|Number} date - the original date
  13. * @returns {Date} the end of a quarter
  14. * @throws {TypeError} 1 argument required
  15. *
  16. * @example
  17. * // The end of a quarter for 2 September 2014 11:55:00:
  18. * const result = endOfQuarter(new Date(2014, 8, 2, 11, 55, 0))
  19. * //=> Tue Sep 30 2014 23:59:59.999
  20. */
  21. export default function endOfQuarter(dirtyDate) {
  22. requiredArgs(1, arguments);
  23. var date = toDate(dirtyDate);
  24. var currentMonth = date.getMonth();
  25. var month = currentMonth - currentMonth % 3 + 3;
  26. date.setMonth(month, 0);
  27. date.setHours(23, 59, 59, 999);
  28. return date;
  29. }