isThisSecond.mjs 943 B

123456789101112131415161718192021222324252627282930
  1. import { constructNow } from "./constructNow.mjs";
  2. import { isSameSecond } from "./isSameSecond.mjs";
  3. /**
  4. * @name isThisSecond
  5. * @category Second Helpers
  6. * @summary Is the given date in the same second as the current date?
  7. * @pure false
  8. *
  9. * @description
  10. * Is the given date in the same second as the current date?
  11. *
  12. * @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).
  13. *
  14. * @param date - The date to check
  15. *
  16. * @returns The date is in this second
  17. *
  18. * @example
  19. * // If now is 25 September 2014 18:30:15.500,
  20. * // is 25 September 2014 18:30:15.000 in this second?
  21. * const result = isThisSecond(new Date(2014, 8, 25, 18, 30, 15))
  22. * //=> true
  23. */
  24. export function isThisSecond(date) {
  25. return isSameSecond(date, constructNow(date));
  26. }
  27. // Fallback for modularized imports:
  28. export default isThisSecond;