"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMonthWeekInfo = exports.getWeekNumber = exports.inutile = void 0;
const at_op_1 = require("./at-op");
function inutile() {
    return 0;
}
exports.inutile = inutile;
function getWeekNumber(at) {
    if (at) {
        at = new Date(at);
    }
    else {
        at = new Date();
    }
    at.setHours(0, 0, 0, 0);
    // Thursday in current week decides the year.
    at.setDate(at.getDate() + 3 - (at.getDay() + 6) % 7);
    // January 4 is always in week 1.
    const week1 = new Date(at.getFullYear(), 0, 4);
    // Adjust to Thursday in week 1 and count number of weeks from date to week1.
    return 1 + Math.round(((at.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
}
exports.getWeekNumber = getWeekNumber;
function getMonthWeekInfo(at) {
    const lastDay = new Date(at);
    (0, at_op_1.atToMonthEnd)(lastDay);
    const weekIndex = Math.floor(at.getDate() / 7);
    return {
        weekIndex,
        isFirst: weekIndex === 0,
        isLast: Math.floor(lastDay.getDate() / 7) === weekIndex
    };
}
exports.getMonthWeekInfo = getMonthWeekInfo;
