diff options
| author | eug-vs <eugene@eug-vs.xyz> | 2021-12-05 20:13:05 +0300 | 
|---|---|---|
| committer | eug-vs <eugene@eug-vs.xyz> | 2021-12-05 20:13:05 +0300 | 
| commit | 3181772393b7c0b44056886ef6cd14e244ba61de (patch) | |
| tree | 717d28966f67663be13f9241162592d2fa0994f7 | |
| parent | c9861261ab6cfa17b1744b00e9ed4bc12792c681 (diff) | |
| download | which-ui-3181772393b7c0b44056886ef6cd14e244ba61de.tar.gz | |
| -rw-r--r-- | src/components/DateString/compactDateString.ts | 3 | 
1 files changed, 2 insertions, 1 deletions
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);  };  |