diff options
| author | Bobby <[email protected]> | 2024-02-11 21:30:12 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-02-11 21:30:12 -0500 |
| commit | eecd7db0d9caff2131a4d1142a2cf0063acda3a8 (patch) | |
| tree | 10b498e81901a1d973fb1d8ed911e5d4c4f9fdf4 /dev_status/utils.py | |
| parent | 5074ea783da1971926436f7c670273cf6009df33 (diff) | |
| download | thatcomputerscientist-eecd7db0d9caff2131a4d1142a2cf0063acda3a8.tar.xz thatcomputerscientist-eecd7db0d9caff2131a4d1142a2cf0063acda3a8.zip | |
Display commits on Repository View
Diffstat (limited to 'dev_status/utils.py')
| -rw-r--r-- | dev_status/utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/dev_status/utils.py b/dev_status/utils.py new file mode 100644 index 00000000..f271e91b --- /dev/null +++ b/dev_status/utils.py @@ -0,0 +1,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 |
