diff options
author | Frederick Yin <fkfd@fkfd.me> | 2021-10-20 15:41:34 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2021-10-20 15:41:34 +0800 |
commit | fa3f7bad8a21e83618cf528db4c38bbfbdb5d7ad (patch) | |
tree | 14ccfa1ad0842b8e4a2243730988531c41dbe0e0 /jimbrella/utils.py | |
parent | a16226825629734a73220070d8afe908450ed522 (diff) |
Move database utilities to database.py
It may not be a good idea to scatter database utilities around utils.py.
With this in mind, I moved them to database.py as static methods under
the class Database.
Diffstat (limited to 'jimbrella/utils.py')
-rw-r--r-- | jimbrella/utils.py | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/jimbrella/utils.py b/jimbrella/utils.py index 09f0ae2..fc68206 100644 --- a/jimbrella/utils.py +++ b/jimbrella/utils.py @@ -1,20 +1,9 @@ -from datetime import datetime, timedelta -from .config import * +from datetime import timedelta -def group_by_status(umbrellas: list) -> dict: - keys = set([umb["status"] for umb in umbrellas]) - statuses = {} - for key in keys: - statuses[key] = [umb for umb in umbrellas if umb["status"] == key] - return statuses - - -def find_overdue(umbrellas: list) -> list: - now = datetime.now() - return [ - umb - for umb in umbrellas - if umb["lent_at"] is not None - and now - umb["lent_at"] > timedelta(hours=DUE_HOURS) - ] +def human_timedelta(delta: timedelta) -> str: + hours = delta.seconds // 3600 + minutes = delta.seconds % (hours * 3600) // 60 + return ( + f"{delta.days} days, " if delta.days else "" + ) + f"{hours:0>2}:{minutes:0>2}" # zero-pad to two digits |