Last active
May 27, 2018 21:43
-
-
Save samuelantonioli/974e2755c2559fadbec6e9f6a92a8223 to your computer and use it in GitHub Desktop.
python working time snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def is_working_time(dt = None): | |
''' | |
is it currently working time? | |
tuesday at 8am - yes | |
saturday - no | |
''' | |
# | |
# hour ranges e.g. to support lunch break | |
work_hours = [(8, 18),] # 8am-6pm | |
work_days = list(range(5)) | |
# | |
# dt = datetime.datetime instance | |
if dt is None: | |
dt = datetime.datetime.now() | |
week_day = dt.weekday() | |
if not week_day in work_days: | |
return False | |
hour = dt.hour | |
for ranges in work_hours: | |
if ranges[0] <= hour < ranges[1]: | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment