def run_to(self, date, include_month_end): """Output all days before this date""" if self.date == date: return if self.month is None: if self.is_last_month(): return self.month = Month.for_date(date) self.consumer.start_month(self.month) self.months_started += 1 while self.date is None or self.date < (date - datetime.timedelta(days=1)): for d in self.month.days(): if self.date is not None and d <= self.date: continue if d == date: break self.consumer.start_day(d) self.date = d else: if not include_month_end and self.month.next().first_day( ) == date: return self.consumer.end_month(self.month) if self.is_last_month(): self.month = None return self.month = self.month.next() self.consumer.start_month(self.month) self.months_started += 1
def __init__(self, consumer, start_date=None, months=12): if start_date is None: start_date = datetime.date.today() start_month = Month.for_date(start_date) ms = MonthAdapter(PeriodMonthSplitter(consumer), start_month, months) super(MonthCalendarFacade, self).__init__(ms, start=start_date, end=start_month.add(months).first_day())