in src/common/utils.py [0:0]
def time_is_up(initial_time: datetime, current_time: datetime, grace_time: float):
"""Check if timeout is exceeded."""
# Localize datetime objects to UTC if not previously localized
# All timestamps used in this function should be already localized
# Assume timestamp was taken from system local time if there is no localization info
if initial_time is None:
return True
if not initial_time.tzinfo:
logging.warning(
"Timestamp %s is not localized. Please double check that this is expected, localizing to UTC.", initial_time
)
initial_time = initial_time.astimezone(tz=timezone.utc)
if not current_time.tzinfo:
logging.warning(
"Timestamp %s is not localized. Please double check that this is expected, localizing to UTC", current_time
)
current_time = current_time.astimezone(tz=timezone.utc)
time_diff = (current_time - initial_time).total_seconds()
return time_diff >= grace_time