startOfMinute.cjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. exports.startOfMinute = startOfMinute;
  3. var _index = require("./toDate.cjs");
  4. /**
  5. * The {@link startOfMinute} function options.
  6. */
  7. /**
  8. * @name startOfMinute
  9. * @category Minute Helpers
  10. * @summary Return the start of a minute for the given date.
  11. *
  12. * @description
  13. * Return the start of a minute for the given date.
  14. * The result will be in the local timezone.
  15. *
  16. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  17. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  18. *
  19. * @param date - The original date
  20. * @param options - An object with options
  21. *
  22. * @returns The start of a minute
  23. *
  24. * @example
  25. * // The start of a minute for 1 December 2014 22:15:45.400:
  26. * const result = startOfMinute(new Date(2014, 11, 1, 22, 15, 45, 400))
  27. * //=> Mon Dec 01 2014 22:15:00
  28. */
  29. function startOfMinute(date, options) {
  30. const date_ = (0, _index.toDate)(date, options?.in);
  31. date_.setSeconds(0, 0);
  32. return date_;
  33. }