index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import startOfMinute from "../startOfMinute/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isSameMinute
  5. * @category Minute Helpers
  6. * @summary Are the given dates in the same minute?
  7. *
  8. * @description
  9. * Are the given dates in the same minute?
  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 minute
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // Are 4 September 2014 06:30:00 and 4 September 2014 06:30:15
  22. * // in the same minute?
  23. * var result = isSameMinute(
  24. * new Date(2014, 8, 4, 6, 30),
  25. * new Date(2014, 8, 4, 6, 30, 15)
  26. * )
  27. * //=> true
  28. */
  29. export default function isSameMinute(dirtyDateLeft, dirtyDateRight) {
  30. requiredArgs(2, arguments);
  31. var dateLeftStartOfMinute = startOfMinute(dirtyDateLeft);
  32. var dateRightStartOfMinute = startOfMinute(dirtyDateRight);
  33. return dateLeftStartOfMinute.getTime() === dateRightStartOfMinute.getTime();
  34. }