index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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?
  7. *
  8. * @description
  9. * Are the given dates in the same second?
  10. *
  11. * ### v2.0.0 breaking changes:
  12. *
  13. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  14. *
  15. * @param {Date|Number} dateLeft - the first date to check
  16. * @param {Date|Number} dateRight - the second date to check
  17. * @returns {Boolean} the dates are in the same second
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // Are 4 September 2014 06:30:15.000 and 4 September 2014 06:30.15.500
  22. * // in the same second?
  23. * var result = isSameSecond(
  24. * new Date(2014, 8, 4, 6, 30, 15),
  25. * new Date(2014, 8, 4, 6, 30, 15, 500)
  26. * )
  27. * //=> true
  28. */
  29. export default function isSameSecond(dirtyDateLeft, dirtyDateRight) {
  30. requiredArgs(2, arguments);
  31. var dateLeftStartOfSecond = startOfSecond(dirtyDateLeft);
  32. var dateRightStartOfSecond = startOfSecond(dirtyDateRight);
  33. return dateLeftStartOfSecond.getTime() === dateRightStartOfSecond.getTime();
  34. }