From 96979f82456e3cd3a585f6be2342feb3437537f3 Mon Sep 17 00:00:00 2001 From: Arthur Gunn Date: Sun, 13 Dec 2020 18:17:40 +1300 Subject: [PATCH] Fix update period for dates older than a day For dates older than a day, and where `minPeriod` was set, the component updated every `minPeriod`. With this update, dates older than a day are always decided by the `maxPeriod` option. --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 4d1fbae..dbdb785 100644 --- a/src/index.js +++ b/src/index.js @@ -90,13 +90,14 @@ export default function TimeAgo({ : seconds < HOUR ? 1000 * MINUTE : seconds < DAY - ? 1000 * HOUR - : 0 + ? 1000 * HOUR + : Infinity + const period = Math.min( Math.max(unboundPeriod, minPeriod * 1000), maxPeriod * 1000, ) - + if (period) { if (timeoutId) { clearTimeout(timeoutId)