def test_true_for_weeks_on_monday(self): d = get_date('2013-11-04') days = [1, 0, 0, 1, 0, 0, 0, 1] overlaps = true_for_all(days) self.assertEqual(true_for_weeks(days, d), days)
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_true_for_all_not_full(self): arr = [1, 0, 0, 0, 0, 0, 1, 1, 1] self.assertEqual(true_for_all(arr), [1, 0, 0, 0, 0, 0, 1, 1, 0])
def test_true_for_weeks_on_friday(self): d = get_date('2013-11-08') days = [1, 0, 0, 1, 0, 0, 0, 1] overlaps = true_for_all(days) self.assertEqual(true_for_weeks(days, d), [0, 0, 0, 1, 0, 0, 1, 0])
def test_true_for_weeks_on_monday_half(self): d = get_date('2013-11-04') days = [1, 0, 0] overlaps = true_for_all(days) self.assertEqual(true_for_weeks(days, d), [1, 0, 0, 0, 0, 0, 0])