UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

22 lines (21 loc) 820 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isSameISOWeek = void 0; /** * Checks if two dates belong to the same ISO week number. * @author @dailker * @param {Date} a * @param {Date} b * @returns {boolean} */ function isSameISOWeek(a, b) { const getWeek = (d) => { const date = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate())); const dayNum = date.getUTCDay() || 7; date.setUTCDate(date.getUTCDate() + 4 - dayNum); const yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1)); return Math.ceil((((date.getTime() - yearStart.getTime()) / 86400000) + 1) / 7); }; return a.getUTCFullYear() === b.getUTCFullYear() && getWeek(a) === getWeek(b); } exports.isSameISOWeek = isSameISOWeek;