import { DateTime } from 'luxon';
export function formatDateLong(value) {
    try {
        let date = new Date(value);
        const day = date.toLocaleString('default', { day: '2-digit' });
        const month = date.toLocaleString('default', { month: 'short' });
        const year = date.toLocaleString('default', { year: 'numeric' });
        const dayOfWeek = date.toLocaleString('default', { weekday: 'long' });
        return `${day} ${month}, ${year} (${dayOfWeek})`;
    }
    catch (error) {
        return '';
    }
}
export function formatDate(value, formatStr = '') {
    try {
        let date = new Date(value);
        const day = date.toLocaleString('default', { day: '2-digit' });
        const month = date.toLocaleString('default', { month: 'short' });
        const year = date.toLocaleString('default', { year: 'numeric' });
        switch (formatStr.toLowerCase()) {
            case 'mon dd, yyyy':
                return `${day} ${month}, ${year}`;
            case 'dd/mm/yyyy':
                return `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`;
            case 'yyyy-mm-dd':
                return date.toISOString().split('T')[0];
            default:
                return '';
        }
    }
    catch (error) {
        return '';
    }
}
export function getDaysDiff(dateOne, dateTwo) {
    const d1 = new Date(dateOne);
    const d2 = new Date(dateTwo);
    const diff = d2.getTime() - d1.getTime();
    return diff / (1000 * 60 * 60 * 24);
}
/**
 * Creates a Date object based on an ISO 8601 date string.
 * @param dateString A ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]
 * @returns A date object, or null if the format was invalid.
 */
export const getDateFromString = (dateString) => {
    if (!dateString || dateString.length === 0) {
        return null;
    }
    const date = DateTime.fromISO(dateString);
    return date ? date.toJSDate() : null;
};
/**
 * Formats a date string by converting it to a date in the specified time zone,
 * stripping out the time element and returning a localized date string.
 * @param date A Date or ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]
 * @param timeZone An IANA time zone id. If supplied, convert the date into the specified time zone,
 * otherwise convert to local browser time.
 * @returns A date string without time based on the supplied time zone and the
 * user's browser locale settings.
 */
export const getLocalizedDateString = (date, timeZone = 'local') => {
    const convertedDate = date instanceof Date ? date : getDateFromString(date);
    return convertedDate
        ? DateTime.fromJSDate(convertedDate, { zone: timeZone }).toLocaleString(DateTime.DATE_SHORT)
        : '';
};
/**
 * Converts a date string to a date in the specified timezone,
 * and returning a converted date with the localized date and time.
 * @param date A Date or ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]
 * @param timeZone If supplied, convert the date into the specified IANA time zone,
 * otherwise convert to local browser time.
 * @returns A converted date and time based on the user's browser locale settings.
 */
export const getLocalizedDateTime = (date, timeZone = 'local') => {
    const convertedDate = date instanceof Date ? date : getDateFromString(date);
    if (convertedDate === null) {
        return '';
    }
    const convertedDateTime = DateTime.fromJSDate(convertedDate, { zone: timeZone });
    return convertedDateTime;
};
/**
 * Formats a date string by converting it to a date in the specified timezone,
 * and returning a string with the localized date and time.
 * @param date A Date or ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]
 * @param delimiter If supplied, split the date and time by this string when returned.
 * @param timeZone If supplied, convert the date into the specified IANA time zone,
 * otherwise convert to local browser time.
 * @returns A date and time string based on the user's browser locale settings.
 */
export const getLocalizedDateTimeString = (date, delimiter = null, timeZone = 'local', includeOffset = false) => {
    const convertedDate = date instanceof Date ? date : getDateFromString(date);
    if (convertedDate === null) {
        return '';
    }
    const convertedDateTime = DateTime.fromJSDate(convertedDate, { zone: timeZone });
    if (delimiter !== null) {
        return (convertedDateTime.toLocaleString(DateTime.DATE_SHORT) +
            delimiter +
            convertedDateTime.toLocaleString(DateTime.TIME_WITH_SECONDS) +
            (includeOffset ? ' ' + convertedDateTime.offsetNameShort : ''));
    }
    else {
        return (convertedDateTime.toLocaleString(DateTime.DATETIME_SHORT_WITH_SECONDS) +
            (includeOffset ? ' ' + convertedDateTime.offsetNameShort : ''));
    }
};
/**
 * Formats a date string by converting it to a date in the specified time zone,
 * and returning a string as the localized time.
 * @param date A Date or ISO 8601 date string. EX: yyyy-MM-ddThh:mm:ss[Z|offset]
 * @param timeZone An IANA time zone id. If supplied, convert the date into the specified time zone,
 * otherwise convert to local browser time.
 * @returns A time string without the date based on the supplied time zone and user's
 * browser locale settings.
 */
export const getLocalizedTimeString = (date, timeZone = 'local') => {
    const convertedDate = date instanceof Date ? date : getDateFromString(date);
    return convertedDate
        ? DateTime.fromJSDate(convertedDate, { zone: timeZone }).toLocaleString(DateTime.TIME_WITH_SECONDS)
        : '';
};
//# sourceMappingURL=dateUtils.js.map