import { LanguageModel } from "@insite/client-framework/Types/ApiModels";

interface Props {
    dateTime: Date;
    options?: Intl.DateTimeFormatOptions;
    language?: LanguageModel | null;
}

const getLocalizedTime = ({ dateTime, language, options }: Props) => {
    const locale = language?.cultureCode || language?.languageCode;

    try {
        return dateTime.toLocaleTimeString(locale, options);
    } catch {
        return dateTime.toLocaleTimeString(undefined, options);
    }
};

export default getLocalizedTime;
