iso-weeks-year
Version:
Library to view week numbers for a year
20 lines • 882 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.weekNumberToDate = void 0;
const internal_error_1 = require("./error/internal-error");
exports.weekNumberToDate = (date) => {
const isDateValid = date && date instanceof Date && !isNaN(date.valueOf());
if (!isDateValid) {
throw new internal_error_1.InternalError('Error: invalid date!');
}
const copyDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
const dayn = (date.getDay() + 6) % 7;
copyDate.setDate(copyDate.getDate() - dayn + 3);
const firstThursday = copyDate.valueOf();
copyDate.setMonth(0, 1);
if (copyDate.getDay() !== 4) {
copyDate.setMonth(0, 1 + ((4 - copyDate.getDay() + 7) % 7));
}
return 1 + Math.ceil((firstThursday - copyDate.valueOf()) / 604800000);
};
//# sourceMappingURL=weekNumberToDate.js.map