From 3181772393b7c0b44056886ef6cd14e244ba61de Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 5 Dec 2021 20:13:05 +0300 Subject: fix: correctly show timestamps for very old posts --- src/components/DateString/compactDateString.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/DateString/compactDateString.ts b/src/components/DateString/compactDateString.ts index 8bff4b7..29c3c44 100644 --- a/src/components/DateString/compactDateString.ts +++ b/src/components/DateString/compactDateString.ts @@ -15,13 +15,14 @@ const resolve = (value: number, metricIndex = 0): string => { const nextMetric = metrics[metricIndex + 1]; const newValue = value / metric.ratio; - if (newValue < nextMetric.ratio * PRECISION) { + if (newValue < nextMetric?.ratio * PRECISION || !nextMetric) { const rounded = Math.round(newValue); const isPlural = rounded > 1; const count = isPlural ? rounded : 'a'; const ending = isPlural ? 's' : ''; return `${count} ${metric.name}${ending} ago`; } + return resolve(newValue, metricIndex + 1); }; -- cgit v1.2.3