Source code for suitcase_theater.HuntLibrary

"""HuntLibrary.py

Schedule and calendar calculations for determining state of the HL A11 performance space and environs.
"""

import datetime

#================================================================

holidays = [
    datetime.date(2023, 9, 4),     # Labor Day
    datetime.date(2023, 10, 16),   # Mon of Fall Break
    datetime.date(2023, 10, 17),
    datetime.date(2023, 10, 18),
    datetime.date(2023, 10, 19),
    datetime.date(2023, 10, 20),   # Fri of Fall Break
    datetime.date(2023, 11,  7),   # Tue Democracy Day
    datetime.date(2023, 11, 22),   # Wed of Thanksgiving break
    datetime.date(2023, 11, 23),   # Thu of Thanksgiving break
    datetime.date(2023, 11, 24),   # Fri of Thanksgiving break
    ]

class_start_time = datetime.time(14,0,0)   # 2:00 PM
class_end_time   = datetime.time(15,50,0)  # 3:50 PM

#================================================================

[docs] def datetime_properties(now): """Given a datetime object, return a dictionary with the time and a number of properties useful for time-based policy decisions. """ now_date = now.date() # extract a date object now_time = now.time() # extract a time object weekday = now_date.weekday() # Monday is 0, Sunday is 6 hour = now_time.hour minute = now_time.minute result = dict() result['time'] = now result['string'] = now.strftime("%Y-%m-%d %a %b %d %H:%M:%S") # true if the day is on a weekend result['is_weekend'] = (weekday == 5) or (weekday == 6) # true if the date falls on a campus holiday result['is_campus_holiday'] = (now_date in holidays) # true if the time falls during the regular business day on a non-holiday result['is_business_hours'] = (not result['is_weekend'] and (not result['is_campus_holiday']) and (hour >= 8) and (hour < 18)) # true if the date and time fall during class result['is_class_time'] = (((weekday == 1) or (weekday == 3)) # Tue or Thu and (not result['is_campus_holiday']) and (now_time >= class_start_time) and (now_time < class_end_time)) # true if time and date are reasonable for active operation result['is_show_time'] = result['is_business_hours'] and (not result['is_class_time']) and (minute > 49) return result
#================================================================
[docs] def current_time_properties(): """Return a dictionary with the current time and a number of properties useful for time-based policy decisions. """ now = datetime.datetime.now() # datetime() object with both date and time return datetime_properties(now)
#================================================================ # The following section is run when this is loaded as a script. if __name__ == "__main__": def test(sample): print(datetime_properties(sample)) test(datetime.datetime(2023, 8, 28, 17, 59)) test(datetime.datetime(2023, 8, 28, 18, 0)) test(datetime.datetime(2023, 8, 29, 14, 1)) test(datetime.datetime(2023, 9, 3, 4, 0)) test(datetime.datetime(2023, 10, 17, 14, 1))