diff --git a/src/shared/components/time.tsx b/src/shared/components/time.tsx index f88226b..11831fe 100644 --- a/src/shared/components/time.tsx +++ b/src/shared/components/time.tsx @@ -29,6 +29,7 @@ const RELATIVE_UNITS: { seconds: number; unit: Intl.RelativeTimeFormatUnit }[] = const LONG_SHORT_TIME_LENGTH = 11; const MIN_SHORT_TIME_SCALE = 0.65; +const SHORT_RELATIVE_TIME_LOCALES = ['fr', 'ru']; export function Time({ date, short, dateOnly, className, longRelativeClassName, shortFitTargetLength, minShortFitScale }: TimeProps) { const dateObj = date == null ? null : new Date(date); @@ -109,7 +110,7 @@ function timeAgo(date: Date, isShort: boolean | undefined, formatters: TimeForma type TimeFormatters = ReturnType; function createTimeFormatters(locale: string) { - const shortRelativeStyle: Intl.RelativeTimeFormatStyle = locale.toLowerCase().startsWith('ru') ? 'short' : 'narrow'; + const shortRelativeStyle: Intl.RelativeTimeFormatStyle = usesShortRelativeTime(locale) ? 'short' : 'narrow'; return { relativeLong: new Intl.RelativeTimeFormat(locale, { numeric: 'always', style: 'long' }), @@ -134,3 +135,8 @@ function createTimeFormatters(locale: string) { }) }; } + +function usesShortRelativeTime(locale: string) { + const normalizedLocale = locale.toLowerCase(); + return SHORT_RELATIVE_TIME_LOCALES.some((shortLocale) => normalizedLocale === shortLocale || normalizedLocale.startsWith(`${shortLocale}-`)); +}