Skip to content

Commit

Permalink
refactor isSameMinute
Browse files Browse the repository at this point in the history
  • Loading branch information
lemming committed Sep 11, 2023
1 parent 101e166 commit bfb1a6b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,17 +831,13 @@ export function getHoursInDay(d) {
return Math.round((+startOfTheNextDay - +startOfDay) / 3_600_000);
}

export function isSameMinute(d1, d2) {
const _date1 = toDate(d1);
const _date2 = toDate(d2);
export function startOfMinute(d) {
const seconds = d.getSeconds();
const milliseconds = d.getMilliseconds();

const seconds1 = _date1.getSeconds();
const seconds2 = _date2.getSeconds();
const milliseconds1 = _date1.getMilliseconds();
const milliseconds2 = _date2.getMilliseconds();
return toDate(d.getTime() - seconds * 1000 - milliseconds);
}

return (
_date1.getTime() - seconds1 * 1000 - milliseconds1 ===
_date2.getTime() - seconds2 * 1000 - milliseconds2
);
export function isSameMinute(d1, d2) {
return +startOfMinute(d1) === +startOfMinute(d2);
}

0 comments on commit bfb1a6b

Please sign in to comment.