summaryrefslogtreecommitdiff
path: root/jimbrella/utils.py
blob: c7e817636e860296d403155c896e2d96bf3a40af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from datetime import datetime, timedelta


def human_datetime(time: datetime) -> str:
    return "{:%Y-%m-%d %H:%M}".format(time)


def human_timedelta(delta: timedelta) -> str:
    if delta.days == 0:
        days = ""
    elif delta.days == 1:
        days = "1 day, "
    else:
        days = f"{delta.days} days, "

    hours = delta.seconds // 3600
    minutes = delta.seconds % (hours * 3600) // 60
    return days + f"{hours:0>2}:{minutes:0>2}"  # zero-pad to two digits