mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
add tests for sqlitemanager util class
+ implement pendulum in date_string_to_time_passed() + remove unused bisection_search_string
This commit is contained in:
+3
-25
@@ -6,7 +6,9 @@ class UseBisection:
|
||||
items.
|
||||
"""
|
||||
|
||||
def __init__(self, source: list, search_from: str, queries: list[str], limit=-1) -> None:
|
||||
def __init__(
|
||||
self, source: list, search_from: str, queries: list[str], limit=-1
|
||||
) -> None:
|
||||
self.source_list = source
|
||||
self.queries_list = queries
|
||||
self.attr = search_from
|
||||
@@ -45,27 +47,3 @@ class UseBisection:
|
||||
break
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def bisection_search_string(strings: list[str], target: str) -> str | None:
|
||||
"""
|
||||
Finds a string in a list of strings using bisection search.
|
||||
"""
|
||||
if not strings:
|
||||
return None
|
||||
|
||||
strings = sorted(strings)
|
||||
|
||||
left = 0
|
||||
right = len(strings) - 1
|
||||
while left <= right:
|
||||
middle = (left + right) // 2
|
||||
if strings[middle] == target:
|
||||
return strings[middle]
|
||||
|
||||
if strings[middle] < target:
|
||||
left = middle + 1
|
||||
else:
|
||||
right = middle - 1
|
||||
|
||||
return None
|
||||
|
||||
+3
-40
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user