def test_add_days(): datum = Datum() datum.today() datum.start_of_day() today = datetime.today() #day = today.day + 1 tomorrow = today + relativedelta(days=1) tomorrow = tomorrow.replace(hour=0, minute=0, second=0, microsecond=0) actual = datum.add_days(1) assert actual == tomorrow
def handle_friday(next_date: Datum, period: str, mult: int, start_date: Datum): """ Extracted the calculation for when the next_day is Friday """ assert isinstance(next_date, Datum) assert isinstance(start_date, Datum) # Starting from line 220. tmp_sat = next_date.clone() tmp_sat.add_days(1) tmp_sun = next_date.clone() tmp_sun.add_days(2) if period == RecurrencePeriod.END_OF_MONTH.value: if (next_date.is_end_of_month() or tmp_sat.is_end_of_month() or tmp_sun.is_end_of_month()): next_date.add_months(1) else: next_date.add_months(mult - 1) else: if tmp_sat.get_day_name() == start_date.get_day_name(): next_date.add_days(1) next_date.add_months(mult) elif tmp_sun.get_day_name() == start_date.get_day_name(): next_date.add_days(2) next_date.add_months(mult) elif next_date.get_day() >= start_date.get_day(): next_date.add_months(mult) elif next_date.is_end_of_month(): next_date.add_months(mult) elif tmp_sat.is_end_of_month(): next_date.add_days(1) next_date.add_months(mult) elif tmp_sun.is_end_of_month(): next_date.add_days(2) next_date.add_months(mult) else: # /* one fewer month fwd because of the occurrence in this month */ next_date.subtract_months(1) return next_date