Not Exported
function getISOWeek(date: Date): number {
const d = new Date(date.getTime());
d.setHours(0, 0, 0, 0);
// Thursday in current week decides the year
d.setDate(d.getDate() + 3 - ((d.getDay() + 6) % 7));
// January 4 is always in week 1
const week1 = new Date(d.getFullYear(), 0, 4);
// Adjust to Thursday in week 1 and count number of weeks from date to week1
return (
1 +
Math.round(
((d.getTime() - week1.getTime()) / 86400000 -
3 +
((week1.getDay() + 6) % 7)) /
7,
)
);
}
Gets the ISO week number from a date