add tests for sqlitemanager util class

+ implement pendulum in date_string_to_time_passed()
+ remove unused bisection_search_string
This commit is contained in:
mungai-njoroge
2023-06-21 12:18:19 +03:00
parent 9d4f7af581
commit 4d310c39c3
10 changed files with 186 additions and 161 deletions
+3 -40
View File
@@ -1,3 +1,4 @@
import pendulum
from datetime import datetime
_format = "%Y-%m-%d %H:%M:%S"
@@ -21,44 +22,6 @@ def date_string_to_time_passed(prev_date: str) -> str:
diff = now - then
seconds = diff.seconds
print(seconds)
if seconds < 0:
return "from the future 🛸"
if seconds < 15:
return "now"
if seconds < 60:
return f"{int(seconds)} seconds ago"
if seconds < 3600:
return f"{int(seconds // 60)} minutes ago"
if seconds < 86400:
return f"{int(seconds // 3600)} hours ago"
days = diff.days
if days == 1:
return "yesterday"
if days < 7:
return f"{days} days ago"
if days < 14:
return "1 week ago"
if days < 30:
return f"{int(days // 7)} weeks ago"
if days < 60:
return "1 month ago"
if days < 365:
return f"{int(days // 30)} months ago"
if days < 730:
return "1 year ago"
return f"{int(days // 365)} years ago"
now = pendulum.now()
return now.subtract(seconds=seconds).diff_for_humans()