Skip to content

Commit

Permalink
fix(date): Calculating now inside function instead of in default para…
Browse files Browse the repository at this point in the history
…meter because of caching
  • Loading branch information
Nickelza committed Dec 26, 2023
1 parent 8735e11 commit 4acafe8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/service/date_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down

0 comments on commit 4acafe8

Please sign in to comment.