/** Checks if the provided value is a valid date */
export function isValidDate(value) {
    return `${new Date(value)}` !== 'Invalid Date';
}
/** Formats the date to ISO format: 'yyyy-mm-dd' */
export function formatIsoDate(date) {
    const d = new Date(date);
    if (!isValidDate(d))
        return undefined;
    const yyyy = d?.getFullYear();
    const mm = (d.getMonth() + 1).toString().padStart(2, '0');
    const dd = d.getDate().toString().padStart(2, '0');
    return `${yyyy}-${mm}-${dd}`;
}
/**
 * Parses string date with the iso format of YYYY-mm-dd
 * @param input string
 * @returns Date | undefined
 */
export function parseIsoDate(input) {
    if (!input)
        return;
    const ticks = Date.parse(input);
    return isNaN(ticks) ? undefined : new Date(ticks);
}
/**
 * Validation for 'YYYY-MM-DD' format
 */
export function validateDateFormat(dateString) {
    const regEx = /^\d{4}-\d{2}-\d{2}$/;
    return dateString.match(regEx);
}
// Get current time's UTC year, month, date
export const getDateUTCValue = (date) => ({
    utcYear: date.getUTCFullYear(),
    utcMonth: date.getUTCMonth(),
    utcDate: date.getUTCDate(),
});
// Generate a date by set its utc value
export const generateDateByUTCValue = (year, month, day) => {
    return day ? new Date(Date.UTC(year, month, day)) : new Date(Date.UTC(year, month));
};
export const sameYearSameMonth = (a, b) => {
    if (!a || !b)
        return false;
    return a.getUTCFullYear() === b.getUTCFullYear() && a.getUTCMonth() === b.getUTCMonth();
};
export const sameYear = (a, b) => {
    if (!a || !b)
        return false;
    return a.getUTCFullYear() === b.getUTCFullYear() ? true : false;
};
export const sameDate = (a, b) => {
    if (!a || !b)
        return false;
    return (a.getUTCFullYear() === b.getUTCFullYear() &&
        a.getUTCMonth() === b.getUTCMonth() &&
        a.getUTCDate() === b.getUTCDate());
};
export const utcDateToLocale = (utcDate) => {
    if (!utcDate)
        return undefined;
    const localDateSameDay = new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate());
    return localDateSameDay.toLocaleDateString();
};
export const getCurrentYear = () => {
    const currentDate = new Date();
    return currentDate.getFullYear();
};
//# sourceMappingURL=dates.js.map