mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
add time ago on recent items
+ move to waitress wsgi server + refactor dates utils + create locustfile for stress test
This commit is contained in:
+23
-4
@@ -1,9 +1,20 @@
|
||||
import pendulum
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
|
||||
def timestamp_from_days_ago(days_ago: int):
|
||||
"""
|
||||
Returns a timestamp from a number of days ago.
|
||||
"""
|
||||
current_datetime = datetime.now()
|
||||
delta = timedelta(days=days_ago)
|
||||
past_timestamp = current_datetime - delta
|
||||
|
||||
return int(past_timestamp.timestamp())
|
||||
|
||||
|
||||
def create_new_date(date: datetime = None) -> str:
|
||||
"""
|
||||
Creates a new date and time string in the format of "YYYY-MM-DD HH:MM:SS"
|
||||
@@ -15,18 +26,26 @@ def create_new_date(date: datetime = None) -> str:
|
||||
return date.strftime(_format)
|
||||
|
||||
|
||||
def date_string_to_time_passed(prev_date: str) -> str:
|
||||
def timestamp_to_time_passed(timestamp: str):
|
||||
"""
|
||||
Converts a date string to time passed. e.g. 2 minutes ago, 1 hour ago, yesterday, 2 days ago, 2 weeks ago, etc.
|
||||
Converts a timestamp to time passed. e.g. 2 minutes ago, 1 hour ago, yesterday, 2 days ago, 2 weeks ago, etc.
|
||||
"""
|
||||
now = datetime.now().timestamp()
|
||||
then = datetime.strptime(prev_date, _format).timestamp()
|
||||
then = datetime.fromtimestamp(int(timestamp)).timestamp()
|
||||
|
||||
diff = now - then
|
||||
now = pendulum.now()
|
||||
return now.subtract(seconds=diff).diff_for_humans()
|
||||
|
||||
|
||||
def date_string_to_time_passed(prev_date: str) -> str:
|
||||
"""
|
||||
Converts a date string to time passed. e.g. 2 minutes ago, 1 hour ago, yesterday, 2 days ago, 2 weeks ago, etc.
|
||||
"""
|
||||
then = datetime.strptime(prev_date, _format).timestamp()
|
||||
return timestamp_to_time_passed(then)
|
||||
|
||||
|
||||
def seconds_to_time_string(seconds):
|
||||
"""
|
||||
Converts seconds to a time string. e.g. 1 hour 2 minutes, 1 hour 2 seconds, 1 hour, 1 minute 2 seconds, etc.
|
||||
|
||||
Reference in New Issue
Block a user