Exemplo n.º 1
0
    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'])
Exemplo n.º 2
0
    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'])
Exemplo n.º 3
0
    def test_get_dates(self):
        first_date = get_date('2013-11-03')
        arr = [1, 0, 0, 1]
        res = get_dates(arr, first_date)

        self.assertEqual(res[0], first_date)
        self.assertEqual(res[1], first_date + timedelta(days=3))
Exemplo n.º 4
0
    def test_get_dates(self):
        first_date = get_date('2013-11-03')
        arr = [1, 0, 0, 1]
        res = get_dates(arr, first_date)

        self.assertEqual(res[0], first_date)
        self.assertEqual(res[1], first_date + timedelta(days=3))