in src/braket/aws/aws_device.py [0:0]
def is_available(self) -> bool:
"""bool: Return if the device is currently available"""
if self.status != "ONLINE":
return False
is_available_result = False
current_datetime_utc = datetime.utcnow()
for execution_window in self.properties.service.executionWindows:
weekday = current_datetime_utc.weekday()
current_time_utc = current_datetime_utc.time().replace(microsecond=0)
if (
execution_window.windowEndHour < execution_window.windowStartHour
and current_time_utc < execution_window.windowEndHour
):
weekday = (weekday - 1) % 7
matched_day = execution_window.executionDay == ExecutionDay.EVERYDAY
matched_day = matched_day or (
execution_window.executionDay == ExecutionDay.WEEKDAYS and weekday < 5
)
matched_day = matched_day or (
execution_window.executionDay == ExecutionDay.WEEKENDS and weekday > 4
)
ordered_days = (
ExecutionDay.MONDAY,
ExecutionDay.TUESDAY,
ExecutionDay.WEDNESDAY,
ExecutionDay.THURSDAY,
ExecutionDay.FRIDAY,
ExecutionDay.SATURDAY,
ExecutionDay.SUNDAY,
)
matched_day = matched_day or (
execution_window.executionDay in ordered_days
and ordered_days.index(execution_window.executionDay) == weekday
)
matched_time = (
execution_window.windowStartHour < execution_window.windowEndHour
and execution_window.windowStartHour
<= current_time_utc
<= execution_window.windowEndHour
) or (
execution_window.windowEndHour < execution_window.windowStartHour
and (
current_time_utc >= execution_window.windowStartHour
or current_time_utc <= execution_window.windowEndHour
)
)
is_available_result = is_available_result or (matched_day and matched_time)
return is_available_result