OK, weird, I'm not sure how it calculated a '6' there. I'll see if I can find a better function for the week of the month.
EDIT: I found several, but they all seem to have one flaw or another. This one looks like the best I've found so far.
def week_number_of_month(date): """ Compute which week of the month a given date is in. Taken from the page at https://stackoverflow.com/a/34297954/727708.""" first_day = date.replace(day=1) day_of_month = date.day if(first_day.weekday() == 6): adjusted_dom = (1 + first_day.weekday()) / 7 else: adjusted_dom = day_of_month + first_day.weekday() return int(ceil(adjusted_dom/7.0))