UNPKG

1.32 kBJavaScriptView Raw
1import { startOfSecond } from "./startOfSecond.js";
2
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 laterDate - The first date to check
12 * @param earlierDate - The second date to check
13 *
14 * @returns The dates are in the same second (and hour and day)
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 */
40export function isSameSecond(laterDate, earlierDate) {
41 return +startOfSecond(laterDate) === +startOfSecond(earlierDate);
42}
43
44// Fallback for modularized imports:
45export default isSameSecond;