import moment from 'moment' import getMeta from '@/utils/meta' // Set moment's display locale to match the app language so that // fromNow() returns "il y a 2 jours" rather than "2 days ago", etc. const _lang = getMeta('ol-i18n')?.currentLangCode ?? 'en' if (_lang !== 'en') { import(`moment/locale/${_lang}`) .then(() => { moment.locale(_lang) }) .catch(() => { /* fall back to English */ }) } export function formatDate(date: moment.MomentInput, format?: string) { if (!date) return 'N/A' if (format == null) { format = 'Do MMM YYYY, h:mm a' } return moment(date).format(format) } export function fromNowDate(date: moment.MomentInput | string) { return moment(date).fromNow() }