From e79b5092fc147532c23d02d2e0d8d9f5d5f3eaa8 Mon Sep 17 00:00:00 2001 From: osmarks Date: Mon, 14 Jun 2021 18:17:31 +0000 Subject: limit to two components used in timestamp --- apioforum/fuzzy.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apioforum/fuzzy.py b/apioforum/fuzzy.py index 94e99c9..8396b8f 100644 --- a/apioforum/fuzzy.py +++ b/apioforum/fuzzy.py @@ -16,6 +16,7 @@ def fuzzy(seconds, ago=False): elif isinstance(seconds, datetime): seconds = (seconds.replace(tzinfo=timezone.utc) - datetime.now(tz=timezone.utc)).total_seconds() + components_used = 0 fmt = "{}" buf = "" if ago: @@ -24,9 +25,11 @@ def fuzzy(seconds, ago=False): seconds = abs(seconds) for short, _, _, unit_length in units: if seconds >= unit_length: + components_used += 1 qty = seconds // unit_length buf += str(int(qty)) + short seconds -= qty * unit_length + if components_used == 2: break if not buf: return "now" return fmt.format(buf) -- cgit v1.2.3