export function convertDateToDateOnlyString(date: Date | undefined) {
    if (!date) {
        return "";
    }

    const month = date.getMonth() + 1;
    const monthString = month < 10 ? `0${month}` : month;
    const day = date.getDate();
    const dateString = day < 10 ? `0${day}` : day;

    return `${date.getFullYear()}-${monthString}-${dateString}`;
}

export function convertDateOnlyStringToDate(dateString: string | undefined) {
    if (!dateString) {
        return undefined;
    }

    const date = new Date(dateString);
    return new Date(date.getTime() + date.getTimezoneOffset() * 60000);
}

export const isMonthAndYearBeforeToday = (month: number, year: number) => {
    const today = new Date();
    const currentMonth = today.getMonth();
    const currentYear = today.getFullYear();
    return year < currentYear || (year === currentYear && month < currentMonth + 1);
};
