Source code for uw.local.util.uw_business_day

"""
Defines some helper function using the uw_business_days table.
"""

from datetime import date, timedelta

[docs]def non_business_days_in_span (cursor, startdate=None, months=4, holidays_only=False): """Returns a list of non-work days between the start & # months (inclusive) :param cursor: a database cursor :param startdate: a datetime date :param enddate: a datetime date :param boolean holidays_only: only include special holidays? (i.e. not weekends) """ if startdate is None: startdate = date.today () enddate = startdate + timedelta (days=months*30) query_condition = " AND holiday_code is not NULL " if holidays_only else "" result = cursor.execute_tuples ("select date FROM uw_date WHERE %(startdate)s <= date AND date <= %(enddate)s AND business_day is NULL {}ORDER by date ASC".format (query_condition), enddate=enddate, startdate=startdate) return [d.date for d in result]