blob: 6e02d1aa4521c1a9d7e4cfd3f03e905abc268368 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
from datetime import datetime, timedelta, timezone
def human_datetime(time: datetime) -> str:
return "{:%Y-%m-%d %H:%M:%S}".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
if hours == 0 and minutes == 0:
return "<1 minute"
if hours == 0:
return days + f"{minutes}min"
return days + f"{hours}h {minutes}min"
CST = timezone(timedelta(hours=8))
|