blob: f271e91b9b25ef41ee57be2427f8c5343269c178 (
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
|
from datetime import datetime
def relative_date(entry):
committedDate = datetime.strptime(
entry["commit"]["committedDate"], "%Y-%m-%dT%H:%M:%SZ"
)
now = datetime.now()
diff = now - committedDate
if diff.days > 365:
entry["commit"]["committedDate"] = str(diff.days // 365) + " years ago"
elif diff.days > 30:
entry["commit"]["committedDate"] = str(diff.days // 30) + " months ago"
elif diff.days > 7:
entry["commit"]["committedDate"] = str(diff.days // 7) + " weeks ago"
elif diff.days > 0:
entry["commit"]["committedDate"] = str(diff.days) + " days ago"
elif diff.seconds > 3600:
entry["commit"]["committedDate"] = str(diff.seconds // 3600) + " hours ago"
elif diff.seconds > 60:
entry["commit"]["committedDate"] = str(diff.seconds // 60) + " minutes ago"
else:
entry["commit"]["committedDate"] = "just now"
return entry
|