index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isEqual
  5. * @category Common Helpers
  6. * @summary Are the given dates equal?
  7. *
  8. * @description
  9. * Are the given dates equal?
  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 compare
  16. * @param {Date|Number} dateRight - the second date to compare
  17. * @returns {Boolean} the dates are equal
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // Are 2 July 2014 06:30:45.000 and 2 July 2014 06:30:45.500 equal?
  22. * var result = isEqual(
  23. * new Date(2014, 6, 2, 6, 30, 45, 0),
  24. * new Date(2014, 6, 2, 6, 30, 45, 500)
  25. * )
  26. * //=> false
  27. */
  28. export default function isEqual(dirtyLeftDate, dirtyRightDate) {
  29. requiredArgs(2, arguments);
  30. var dateLeft = toDate(dirtyLeftDate);
  31. var dateRight = toDate(dirtyRightDate);
  32. return dateLeft.getTime() === dateRight.getTime();
  33. }