Skip to content

Instantly share code, notes, and snippets.

@samuelantonioli
Last active May 27, 2018 21:43
Show Gist options
  • Save samuelantonioli/974e2755c2559fadbec6e9f6a92a8223 to your computer and use it in GitHub Desktop.
Save samuelantonioli/974e2755c2559fadbec6e9f6a92a8223 to your computer and use it in GitHub Desktop.
python working time snippet
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