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.
19 lines (18 loc) • 746 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertDateToISOWeekString = void 0;
/**
* Returns string like 2025-W26 for the ISO week.
* @author @dailker
* @param {Date} date
* @returns {string}
*/
function convertDateToISOWeekString(date) {
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
const dayNum = d.getUTCDay() || 7;
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
const week = Math.ceil((((d.getTime() - yearStart.getTime()) / 86400000) + 1) / 7);
return `${d.getUTCFullYear()}-W${week}`;
}
exports.convertDateToISOWeekString = convertDateToISOWeekString;