index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import startOfSecond from "../startOfSecond/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isSameSecond
  5. * @category Second Helpers
  6. * @summary Are the given dates in the same second (and hour and day)?
  7. *
  8. * @description
  9. * Are the given dates in the same second (and hour and day)?
  10. *
  11. * @param {Date|Number} dateLeft - the first date to check
  12. * @param {Date|Number} dateRight - the second date to check
  13. * @returns {Boolean} the dates are in the same second (and hour and day)
  14. * @throws {TypeError} 2 arguments required
  15. *
  16. * @example
  17. * // Are 4 September 2014 06:30:15.000 and 4 September 2014 06:30.15.500 in the same second?
  18. * const result = isSameSecond(
  19. * new Date(2014, 8, 4, 6, 30, 15),
  20. * new Date(2014, 8, 4, 6, 30, 15, 500)
  21. * )
  22. * //=> true
  23. *
  24. * @example
  25. * // Are 4 September 2014 06:00:15.000 and 4 September 2014 06:01.15.000 in the same second?
  26. * const result = isSameSecond(
  27. * new Date(2014, 8, 4, 6, 0, 15),
  28. * new Date(2014, 8, 4, 6, 1, 15)
  29. * )
  30. * //=> false
  31. *
  32. * @example
  33. * // Are 4 September 2014 06:00:15.000 and 5 September 2014 06:00.15.000 in the same second?
  34. * const result = isSameSecond(
  35. * new Date(2014, 8, 4, 6, 0, 15),
  36. * new Date(2014, 8, 5, 6, 0, 15)
  37. * )
  38. * //=> false
  39. */
  40. export default function isSameSecond(dirtyDateLeft, dirtyDateRight) {
  41. requiredArgs(2, arguments);
  42. var dateLeftStartOfSecond = startOfSecond(dirtyDateLeft);
  43. var dateRightStartOfSecond = startOfSecond(dirtyDateRight);
  44. return dateLeftStartOfSecond.getTime() === dateRightStartOfSecond.getTime();
  45. }