/**
 * Generates an array of Date objects representing each day within a specified month and year.
 * This function is useful for generating calendars or performing date-related operations
 * that require knowledge of all the days within a particular month.
 *
 * The function operates by:
 * 1. Creating a Date object set to the first day of the specified month and year.
 * 2. Iterating from the first day until the last day of the month. For each day:
 *    a. A new Date object is created for the current day and added to the `days` array.
 *    b. The date is incremented by one day.
 * 3. The loop continues until the month of the incremented date no longer matches the specified month,
 *    indicating that the end of the month has been reached.
 * 4. Finally, the function returns the array of Date objects.
 *
 * Note: The month parameter is zero-based, meaning January is 0 and December is 11, following JavaScript's Date object convention.
 *
 * @public
 * @param year - The year of the month for which to generate the days.
 * @param month - The zero-based index of the month for which to generate the days (0 = January, 11 = December).
 * @returns An array of Date objects, each representing a day in the specified month and year.

 */
export function getDaysOfMonth(year, month) {
    const date = new Date(year, month, 1);
    const days = [];
    while (date.getMonth() === month) {
        days.push(new Date(date));
        date.setDate(date.getDate() + 1);
    }
    return days;
}
/**
 * Calculates the ISO week number for a given date.
 * The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard.
 * The first week of the year is the week that contains the first Thursday of the year.
 *
 * The function works as follows:
 * 1. It calculates the date of the first day of the year (January 1st) for the given date.
 * 2. It calculates the number of days passed since January 1st until the given date.
 * 3. The days passed, along with the day of the week of January 1st, are used to calculate the week number.
 *    This calculation considers the start of the week (Monday) and adjusts the calculation to ensure
 *    that the first week of the year contains January 4th, which is a requirement for the week to be considered
 *    the first week according to ISO 8601.
 *
 * Note: This function assumes the week starts on Monday, which is consistent with the ISO 8601 standard.
 *
 * @public
 * @param date - The date for which to calculate the week number.
 * @returns The ISO week number of the year for the given date.
 */
export function getWeekNumber(date) {
    const janFirst = new Date(date.getFullYear(), 0, 1);
    const daysPassed = (date.getTime() - janFirst.getTime()) / (24 * 60 * 60 * 1000);
    return Math.ceil((daysPassed + janFirst.getDay() + 1) / 7);
}
/**
 * Generates a mapping of weekday indices to their names according to a specified locale and format.
 * This function is versatile for applications needing to display or utilize localized weekday names
 * in various formats (such as "long", "short", etc.), providing a straightforward way to retrieve
 * day names in a specific locale.
 *
 * The function operates by:
 * 1. Creating an empty object to store the mapping of day indices to names.
 * 2. Looping through each day of the week, starting from 0 (Sunday) to 6 (Saturday).
 *    a. For each day, a specific date is chosen where June 6, 2021, is known to be a Sunday.
 *       This arbitrary date ensures consistency in obtaining the day names across different locales.
 *    b. The `Intl.DateTimeFormat` object, configured with the specified locale and weekday format,
 *       is used to format the name of each day.
 *    c. Each formatted day name is then stored in the object with its corresponding index.
 * 3. After populating the object with all day names, the function returns the object.
 *
 * Example usage:
 * ```
 * const dayNames = getDayNames('en-US');
 * // Returns {0: "Sunday", 1: "Monday", 2: "Tuesday", 3: "Wednesday", 4: "Thursday", 5: "Friday", 6: "Saturday"}
 * // for the en-US locale with the default "long" format.
 * ```
 * @public
 * @param locale - A string representing the locale to use for formatting the day names.
 *                 Examples include "en-US" for English (United States), "fr-FR" for French (France), etc.
 * @param format - An optional parameter specifying the format of the weekday names.
 *                 Can be "long" (default), "short", or "narrow".
 *                 For example, the "long" format for the English (United States) locale would yield "Sunday",
 *                 while the "short" format would yield "Sun".
 * @returns A `Record<number, string>` object where each key is a numeric index representing the day of the week
 *          (0 for Sunday through 6 for Saturday) and each value is the corresponding localized day name in the specified format.
 */
export function getDayNames(locale, format = 'long') {
    const dayNames = {};
    for (let day = 0; day < 7; day++) {
        const date = new Date(Date.UTC(2021, 5, 6 + day)); // Arbitrary date where June 6, 2021, is a Sunday
        const dayName = new Intl.DateTimeFormat(locale, { weekday: format }).format(date);
        dayNames[day] = dayName;
    }
    return dayNames;
}
export function isDateEqual(date1, date2) {
    return date1.getDate() === date2.getDate() && date1.getMonth() === date2.getMonth() && date1.getFullYear() === date2.getFullYear();
}
export function dayNames(names, firstDayOfWeek) {
    const rotatedDayNames = [
        ...names.slice(firstDayOfWeek),
        ...names.slice(0, firstDayOfWeek)
    ];
    return rotatedDayNames;
}
export function isToday(date) {
    const today = new Date();
    today.setHours(0, 0, 0, 0); // Reset to midnight
    return isDateEqual(date, today);
}
export function isDateInDates(date, dates) {
    return dates.some((d) => isDateEqual(d, date));
}
export function isWeekendDay(date) {
    return date.getDay() === 0 || date.getDay() === 6;
}
export function isWeekDay(date) {
    return !isWeekendDay(date);
}
export function getDateOnly(date) {
    let isValidDate = false;
    if (date instanceof Date) {
        isValidDate = !isNaN(date.getTime());
    }
    else {
        isValidDate = false;
    }
    const validDate = isValidDate ? date : new Date();
    return new Date(validDate.getFullYear(), validDate.getMonth(), validDate.getDate());
}
//# sourceMappingURL=Utils.js.map