From 4acafe841f698350084178a411dc677d8f75befa Mon Sep 17 00:00:00 2001 From: Nickelza Date: Tue, 26 Dec 2023 15:19:06 +0100 Subject: [PATCH] fix(date): Calculating now inside function instead of in default parameter because of caching --- src/service/date_service.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/service/date_service.py b/src/service/date_service.py index 72faf439..e1aaae37 100644 --- a/src/service/date_service.py +++ b/src/service/date_service.py @@ -118,7 +118,7 @@ def cron_datetime_difference(cron_expression: str, start_datetime: datetime = No return convert_seconds_to_duration((next_run - start_datetime).total_seconds()) -def get_remaining_duration(end_datetime: datetime, start_datetime: datetime.datetime = datetime.datetime.now()) -> str: +def get_remaining_duration(end_datetime: datetime, start_datetime: datetime.datetime = None) -> str: """ Get the remaining time until the end_datetime :param end_datetime: The end datetime @@ -128,6 +128,9 @@ def get_remaining_duration(end_datetime: datetime, start_datetime: datetime.date if end_datetime is None: return convert_seconds_to_duration(0) + if start_datetime is None: + start_datetime = datetime.datetime.now() + # Remove offset awareness from end_datetime end_datetime = end_datetime.replace(tzinfo=None) return convert_seconds_to_duration((end_datetime - start_datetime).total_seconds())