Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
33 lines
1.2 KiB
Plaintext
33 lines
1.2 KiB
Plaintext
import { TZDateMini as TZDate } from '@date-fns/tz/date/mini';
|
|
import { format, formatDistanceToNow, transpose } from 'date-fns';
|
|
export const formatDate = ({
|
|
date,
|
|
i18n,
|
|
pattern,
|
|
timezone
|
|
}) => {
|
|
const theDate = new TZDate(new Date(date));
|
|
if (timezone) {
|
|
const DateWithOriginalTz = TZDate.tz(timezone);
|
|
const modifiedDate = theDate.withTimeZone(timezone);
|
|
// Transpose the date to the selected timezone
|
|
const dateWithTimezone = transpose(modifiedDate, DateWithOriginalTz);
|
|
// Transpose the date to the user's timezone - this is necessary because the react-datepicker component insists on displaying the date in the user's timezone
|
|
return i18n.dateFNS ? format(dateWithTimezone, pattern, {
|
|
locale: i18n.dateFNS
|
|
}) : `${i18n.t('general:loading')}...`;
|
|
}
|
|
return i18n.dateFNS ? format(theDate, pattern, {
|
|
locale: i18n.dateFNS
|
|
}) : `${i18n.t('general:loading')}...`;
|
|
};
|
|
export const formatTimeToNow = ({
|
|
date,
|
|
i18n
|
|
}) => {
|
|
const theDate = typeof date === 'string' ? new Date(date) : date;
|
|
return i18n?.dateFNS ? formatDistanceToNow(theDate, {
|
|
locale: i18n.dateFNS
|
|
}) : `${i18n.t('general:loading')}...`;
|
|
};
|
|
//# sourceMappingURL=formatDateTitle.js.map |