diff options
author | osmarks <osmarks> | 2021-06-14 18:17:31 +0000 |
---|---|---|
committer | osmarks <osmarks> | 2021-06-14 18:17:31 +0000 |
commit | e79b5092fc147532c23d02d2e0d8d9f5d5f3eaa8 (patch) | |
tree | 5bd0605a88407c0def4c64d37ccd73b7c8431554 | |
parent | 265d7b3dce72b1c25eb8a64a2a5f8df11a065074 (diff) |
limit to two components used in timestamp
-rw-r--r-- | apioforum/fuzzy.py | 3 |
1 files changed, 3 insertions, 0 deletions
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) |