From 0693ad08f8ea206638bd19d0bd680a0a5892a4ef Mon Sep 17 00:00:00 2001 From: PolariTOON <36267812+PolariTOON@users.noreply.github.com> Date: Wed, 7 Dec 2022 13:51:51 +0100 Subject: [PATCH] feat: Add a `formatLocallyDistanceToNowStrict` helper --- react/I18n/format.jsx | 4 ++++ react/Viewer/components/ExpirationAlert.jsx | 4 ++-- react/Viewer/components/ExpirationAnnotation.jsx | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/react/I18n/format.jsx b/react/I18n/format.jsx index 7ede4257fa..ce336047c1 100644 --- a/react/I18n/format.jsx +++ b/react/I18n/format.jsx @@ -1,6 +1,7 @@ import format from 'date-fns/format' import { DEFAULT_LANG } from '.' import formatDistanceToNow from 'date-fns/formatDistanceToNow' +import formatDistanceToNowStrict from 'date-fns/formatDistanceToNowStrict' const locales = {} let lang = DEFAULT_LANG === 'en' ? 'en-US' : DEFAULT_LANG @@ -42,3 +43,6 @@ export const initFormat = (userLang, defaultLang = DEFAULT_LANG) => ( export const formatLocallyDistanceToNow = date => formatDistanceToNow(date, { locale: locales[lang] }) + +export const formatLocallyDistanceToNowStrict = date => + formatDistanceToNowStrict(date, { locale: locales[lang] }) diff --git a/react/Viewer/components/ExpirationAlert.jsx b/react/Viewer/components/ExpirationAlert.jsx index 21b8cc4842..847adef3e5 100644 --- a/react/Viewer/components/ExpirationAlert.jsx +++ b/react/Viewer/components/ExpirationAlert.jsx @@ -9,7 +9,7 @@ import Link from '../../Link' import Typography from '../../Typography' import { withViewerLocales } from '../hoc/withViewerLocales' import { useI18n } from '../../I18n' -import { formatLocallyDistanceToNow } from '../../I18n/format' +import { formatLocallyDistanceToNowStrict } from '../../I18n/format' const FILES_DOCTYPE = 'io.cozy.files' @@ -51,7 +51,7 @@ const ExpirationAlert = ({ file }) => { {t('Viewer.panel.expiration.description', { - duration: formatLocallyDistanceToNow(expirationDate) + duration: formatLocallyDistanceToNowStrict(expirationDate) })} {expirationNoticeLink && ( diff --git a/react/Viewer/components/ExpirationAnnotation.jsx b/react/Viewer/components/ExpirationAnnotation.jsx index 3379d68650..ec18896d9a 100644 --- a/react/Viewer/components/ExpirationAnnotation.jsx +++ b/react/Viewer/components/ExpirationAnnotation.jsx @@ -5,7 +5,7 @@ import { models } from 'cozy-client' import Typography from '../../Typography' import { useI18n } from '../../I18n' -import { formatLocallyDistanceToNow } from '../../I18n/format' +import { formatLocallyDistanceToNowStrict } from '../../I18n/format' const { computeExpirationDate, isExpired } = models.paper @@ -25,7 +25,7 @@ const ExpirationAnnotation = ({ file }) => { return ( {t('Viewer.panel.qualification.expiresIn', { - duration: formatLocallyDistanceToNow(expirationDate) + duration: formatLocallyDistanceToNowStrict(expirationDate) })} )