UNPKG

1.34 kBJavaScriptView Raw
1"use strict";
2exports.isSameMinute = isSameMinute;
3var _index = require("./startOfMinute.js");
4
5/**
6 * @name isSameMinute
7 * @category Minute Helpers
8 * @summary Are the given dates in the same minute (and hour and day)?
9 *
10 * @description
11 * Are the given dates in the same minute (and hour and day)?
12 *
13 * @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).
14 *
15 * @param dateLeft - The first date to check
16 * @param dateRight - The second date to check
17 *
18 * @returns The dates are in the same minute (and hour and day)
19 *
20 * @example
21 * // Are 4 September 2014 06:30:00 and 4 September 2014 06:30:15 in the same minute?
22 * const result = isSameMinute(
23 * new Date(2014, 8, 4, 6, 30),
24 * new Date(2014, 8, 4, 6, 30, 15)
25 * )
26 * //=> true
27 *
28 * @example
29 * // Are 4 September 2014 06:30:00 and 5 September 2014 06:30:00 in the same minute?
30 * const result = isSameMinute(
31 * new Date(2014, 8, 4, 6, 30),
32 * new Date(2014, 8, 5, 6, 30)
33 * )
34 * //=> false
35 */
36function isSameMinute(dateLeft, dateRight) {
37 const dateLeftStartOfMinute = (0, _index.startOfMinute)(dateLeft);
38 const dateRightStartOfMinute = (0, _index.startOfMinute)(dateRight);
39
40 return +dateLeftStartOfMinute === +dateRightStartOfMinute;
41}