index.js 785 B

1234567891011121314151617181920212223242526
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name startOfHour
  5. * @category Hour Helpers
  6. * @summary Return the start of an hour for the given date.
  7. *
  8. * @description
  9. * Return the start of an hour 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 start of an hour
  14. * @throws {TypeError} 1 argument required
  15. *
  16. * @example
  17. * // The start of an hour for 2 September 2014 11:55:00:
  18. * const result = startOfHour(new Date(2014, 8, 2, 11, 55))
  19. * //=> Tue Sep 02 2014 11:00:00
  20. */
  21. export default function startOfHour(dirtyDate) {
  22. requiredArgs(1, arguments);
  23. var date = toDate(dirtyDate);
  24. date.setMinutes(0, 0, 0);
  25. return date;
  26. }