def add_calendar(self, attrs): service_id = attrs['FootnoteId'] first = attrs['Firstdate'] first_date = get_date(first) vector = attrs['Vector'] if not len(vector): null = ["0",] * 7 empty_date = first.replace("-", "") self._store_data("all", "calendar", [service_id,] + null + [empty_date, empty_date]) return end_date = first_date + timedelta(days=len(vector)) days = to_ints(list(vector)) overlaps = true_for_all(days) sub = true_for_some(days) week_overlaps = true_for_weeks(overlaps, first_date)[:7] fd = str(first_date).replace("-", "") ed = str(end_date).replace("-", "") self._store_data("all", "calendar", [service_id,] + map(str, week_overlaps) + [fd, ed]) # add irregular dates for d in get_dates(sub, first_date): self._store_data("all", "calendar_dates", [service_id, str(d).replace("-", ""), '1'])
def add_calendar(self, attrs): service_id = attrs['FootnoteId'] first = attrs['Firstdate'] first_date = get_date(first) vector = attrs['Vector'] if not len(vector): null = [ "0", ] * 7 empty_date = first.replace("-", "") self._store_data("all", "calendar", [ service_id, ] + null + [empty_date, empty_date]) return end_date = first_date + timedelta(days=len(vector)) days = to_ints(list(vector)) overlaps = true_for_all(days) sub = true_for_some(days) week_overlaps = true_for_weeks(overlaps, first_date)[:7] fd = str(first_date).replace("-", "") ed = str(end_date).replace("-", "") self._store_data("all", "calendar", [ service_id, ] + map(str, week_overlaps) + [fd, ed]) # add irregular dates for d in get_dates(sub, first_date): self._store_data( "all", "calendar_dates", [service_id, str(d).replace("-", ""), '1'])
def test_to_ints(self): self.assertEqual(to_ints(list('101')), [1, 0, 1])