Im trying to check two things:
- If the time is between a specified interval.
- And if the current day is a weekday.
I have found this code from this thread:
from datetime import datetime, time
def is_time_between(begin_time, end_time, check_time=None):
# If check time is not given, default to current UTC time
check_time = check_time or datetime.now().time() # datetime.utcnow().time()
if begin_time < end_time:
return check_time >= begin_time and check_time <= end_time
else: # crosses midnight
return check_time >= begin_time or check_time <= end_time
And it works fantastic!
But how to, regardless, return false
if the day is on a saturday or sunday?