Python dateutil.rrule.WEEKLY Examples

The following are 29 code examples of dateutil.rrule.WEEKLY(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module dateutil.rrule , or try the search function .
Example #1
Source File: test_imports.py    From plugin.video.emby with GNU General Public License v3.0 7 votes vote down vote up
def testRRuleAll(self):
        from dateutil.rrule import rrule
        from dateutil.rrule import rruleset
        from dateutil.rrule import rrulestr
        from dateutil.rrule import YEARLY, MONTHLY, WEEKLY, DAILY
        from dateutil.rrule import HOURLY, MINUTELY, SECONDLY
        from dateutil.rrule import MO, TU, WE, TH, FR, SA, SU

        rr_all = (rrule, rruleset, rrulestr,
                  YEARLY, MONTHLY, WEEKLY, DAILY,
                  HOURLY, MINUTELY, SECONDLY,
                  MO, TU, WE, TH, FR, SA, SU)

        for var in rr_all:
            self.assertIsNot(var, None)

        # In the public interface but not in all
        from dateutil.rrule import weekday
        self.assertIsNot(weekday, None) 
Example #2
Source File: recurrence.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _getWhen(self, offset, numDays=1):
        retval = ""
        if self.freq == DAILY:
            retval = self.__getDailyWhen()

        elif self.freq == WEEKLY:
            retval = self.__getWeeklyWhen(offset)

        elif self.freq == MONTHLY:
            retval = self.__getMonthlyWhen(offset)

        elif self.freq == YEARLY:
            retval = self.__getYearlyWhen(offset)

        if numDays >= 2:
            retval += " "+_("for {n} days").format(n=numDays)
        if self.until:
            until = self.until + dt.timedelta(days=offset)
            retval += " "+_("(until {when})").format(when=dateShortFormat(until))
        return retval 
Example #3
Source File: test_imports.py    From bazarr with GNU General Public License v3.0 6 votes vote down vote up
def testRRuleAll(self):
        from dateutil.rrule import rrule
        from dateutil.rrule import rruleset
        from dateutil.rrule import rrulestr
        from dateutil.rrule import YEARLY, MONTHLY, WEEKLY, DAILY
        from dateutil.rrule import HOURLY, MINUTELY, SECONDLY
        from dateutil.rrule import MO, TU, WE, TH, FR, SA, SU

        rr_all = (rrule, rruleset, rrulestr,
                  YEARLY, MONTHLY, WEEKLY, DAILY,
                  HOURLY, MINUTELY, SECONDLY,
                  MO, TU, WE, TH, FR, SA, SU)

        for var in rr_all:
            self.assertIsNot(var, None)

        # In the public interface but not in all
        from dateutil.rrule import weekday
        self.assertIsNot(weekday, None) 
Example #4
Source File: test_activity_series_api.py    From karrot-backend with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_activity_series_create_activates_group(self):
        url = '/api/activity-series/'
        recurrence = rrule.rrule(
            freq=rrule.WEEKLY,
            byweekday=[0, 1]  # Monday and Tuesday
        )
        start_date = self.group.timezone.localize(datetime.now().replace(hour=20, minute=0))
        activity_series_data = {
            'max_participants': 5,
            'place': self.place.id,
            'rule': str(recurrence),
            'start_date': start_date
        }
        self.group.status = GroupStatus.INACTIVE.value
        self.group.save()
        self.client.force_login(user=self.member)
        self.client.post(url, activity_series_data, format='json')
        self.group.refresh_from_db()
        self.assertEqual(self.group.status, GroupStatus.ACTIVE.value) 
Example #5
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_weekly_by_month_year_day(self):
        rule = rrule(
            WEEKLY,
            bymonth=(1, 7),
            byyearday=(1, 100, 200, 365),
            dtstart=datetime.datetime(1997, 9, 2, 9, 0),
        )
        vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
        vRecur(
            vrecurr
        ).to_ical().decode() == "FREQ=WEEKLY;BYYEARDAY=1,100,200,365;BYMONTH=1,7" 
Example #6
Source File: recurrence.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def frequency(self):
        """
        How often the recurrence repeats.
        ("YEARLY", "MONTHLY", "WEEKLY", "DAILY")
        """
        freqOptions = ("YEARLY", "MONTHLY", "WEEKLY", "DAILY")
        if self.rule._freq < len(freqOptions):
            return freqOptions[self.rule._freq]
        else:
            return "unsupported_frequency_{}".format(self.rule._freq) 
Example #7
Source File: test_activity_series_api.py    From karrot-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        self.url = '/api/activity-series/'
        self.series = ActivitySeriesFactory()
        self.series_url = '/api/activity-series/{}/'.format(self.series.id)
        self.non_member = UserFactory()
        self.series_data = {'place': self.series.place.id, 'rule': 'FREQ=WEEKLY', 'start_date': timezone.now()} 
Example #8
Source File: test_activity_series_api.py    From karrot-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_invalid_rule_fails(self):
        url = '/api/activity-series/{}/'.format(self.series.id)
        self.client.force_login(user=self.member)
        response = self.client.patch(url, {'rule': 'FREQ=WEEKLY;BYDAY='})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data) 
Example #9
Source File: test_activity_series_api.py    From karrot-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_set_multiple_rules_fails(self):
        self.client.force_login(user=self.member)
        url = '/api/activity-series/{}/'.format(self.series.id)
        response = self.client.patch(url, {'rule': 'RRULE:FREQ=WEEKLY;BYDAY=MO\nRRULE:FREQ=MONTHLY'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.data)
        self.assertEqual(response.data, {'rule': ['Only single recurrence rules are allowed.']}) 
Example #10
Source File: test_activity_series_api.py    From karrot-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_set_end_date_with_timezone(self):
        self.client.force_login(user=self.member)
        url = '/api/activity-series/{}/'.format(self.series.id)
        rule = 'FREQ=WEEKLY;UNTIL={}+0100'.format((self.now + relativedelta(days=8)).strftime('%Y%m%dT%H%M%S'))
        response = self.client.patch(url, {'rule': rule})
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data) 
Example #11
Source File: test_activity_series_api.py    From karrot-backend with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_set_end_date(self):
        self.client.force_login(user=self.member)
        # change rule
        url = '/api/activity-series/{}/'.format(self.series.id)
        rule = 'FREQ=WEEKLY;UNTIL={}'.format((self.now + relativedelta(days=8)).strftime('%Y%m%dT%H%M%S'))
        response = self.client.patch(url, {'rule': rule})
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertEqual(response.data['rule'], rule)

        # compare resulting activities
        url = '/api/activities/'
        response = self.get_results(url, {'series': self.series.id, 'date_min': self.now})
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.data)
        self.assertEqual(len(response.data), 2, response.data) 
Example #12
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_complex_rule_serialization_with_weekday_instance(self):
        rule = recurrence.Rule(
            recurrence.WEEKLY,
            interval=17,
            wkst=recurrence.to_weekday(1),
            count=7,
            byday=[recurrence.to_weekday("-1MO"), recurrence.to_weekday("TU")],
            bymonth=[1, 3],
        )
        vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
        assert (
            vRecur(vrecurr).to_ical().decode()
            == "FREQ=WEEKLY;COUNT=7;INTERVAL=17;BYDAY=-1MO,TU;BYMONTH=1,3;WKST=TU"
        ) 
Example #13
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_complex_rule_serialization(self):
        rule = recurrence.Rule(
            recurrence.WEEKLY,
            interval=17,
            wkst=1,
            count=7,
            byday=[recurrence.to_weekday("-1MO"), recurrence.to_weekday("TU")],
            bymonth=[1, 3],
        )
        vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
        assert (
            vRecur(vrecurr).to_ical().decode()
            == "FREQ=WEEKLY;COUNT=7;INTERVAL=17;BYDAY=-1MO,TU;BYMONTH=1,3;WKST=TU"
        ) 
Example #14
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_rule(self):
        rule = recurrence.Rule(recurrence.WEEKLY)
        vrecurr = utils.build_rrule_from_recurrences_rrule(rule)
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY" 
Example #15
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_weekly_by_monthday(self):
        rule = rrule(
            WEEKLY,
            count=3,
            bymonthday=(1, 3),
            dtstart=datetime.datetime(1997, 9, 2, 9, 0),
        )
        vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;COUNT=3;BYMONTHDAY=1,3" 
Example #16
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_weekly_by_month_nweekday(self):
        rule = rrule(
            WEEKLY,
            count=3,
            bymonth=(1, 3),
            byweekday=(TU(1), TH(-1)),
            dtstart=datetime.datetime(1997, 9, 2, 9, 0),
        )
        vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
        vRecur(
            vrecurr
        ).to_ical().decode() == "FREQ=WEEKLY;COUNT=3;BYDAY=TU,TH;BYMONTH=1,3" 
Example #17
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_week_20_times(self):
        """Repeat every week for 20 times."""
        vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;COUNT=20")
        assert vrecurr["FREQ"] == ["WEEKLY"]
        assert vrecurr["COUNT"] == [20]
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;COUNT=20"
        assert len(vrecurr.keys()) == 2 
Example #18
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_week_until_jan_2007(self):
        """Repeat every week until January 1, 2007."""
        utc = pytz.UTC
        vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;UNTIL=20070101T000000Z")
        assert vrecurr["FREQ"] == ["WEEKLY"]
        assert vrecurr["UNTIL"] == [datetime.datetime(2007, 1, 1, 0, 0, tzinfo=utc)]
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;UNTIL=20070101T000000Z"
        assert len(vrecurr.keys()) == 2 
Example #19
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_weekday(self):
        """Repeat every weekday."""
        vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR")
        assert vrecurr["FREQ"] == ["WEEKLY"]
        assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR"]
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"
        assert len(vrecurr.keys()) == 2 
Example #20
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_weekly_mo_wed(self):
        """Repeat every week on Monday, Wednesday."""
        vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;BYDAY=MO,WE")
        assert vrecurr["FREQ"] == ["WEEKLY"]
        assert vrecurr["BYDAY"] == ["MO", "WE"]
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=MO,WE"
        assert len(vrecurr.keys()) == 2 
Example #21
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_weekly_tue(self):
        """Repeat every week on Tuesday."""
        vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY;BYDAY=TU")
        assert vrecurr["FREQ"] == ["WEEKLY"]
        assert vrecurr["BYDAY"] == ["TU"]
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=TU"
        assert len(vrecurr.keys()) == 2 
Example #22
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_week(self):
        """Repeat every week."""
        vrecurr = utils.build_rrule_from_text("FREQ=WEEKLY")
        assert vrecurr["FREQ"] == ["WEEKLY"]
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY"
        assert len(vrecurr.keys()) == 1 
Example #23
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_week_20_times(self):
        """Repeat every week for 20 times."""
        vrecurr = utils.build_rrule(freq="WEEKLY", count=20)
        assert vrecurr["FREQ"] == "WEEKLY"
        assert vrecurr["COUNT"] == 20
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;COUNT=20"
        assert len(vrecurr.keys()) == 2 
Example #24
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_2_weeks(self):
        """Repeat every 2 weeks."""
        vrecurr = utils.build_rrule(interval=2, freq="WEEKLY")
        assert vrecurr["FREQ"] == "WEEKLY"
        assert vrecurr["INTERVAL"] == 2
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;INTERVAL=2"
        assert len(vrecurr.keys()) == 2 
Example #25
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_weekday(self):
        """Repeat every weekday."""
        vrecurr = utils.build_rrule(freq="WEEKLY", byday=["MO", "TU", "WE", "TH", "FR"])
        assert vrecurr["FREQ"] == "WEEKLY"
        assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR"]
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"
        assert len(vrecurr.keys()) == 2 
Example #26
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_weekly_mo_wed(self):
        """Repeat every week on Monday, Wednesday."""
        vrecurr = utils.build_rrule(freq="WEEKLY", byday=["MO", "WE"])
        assert vrecurr["FREQ"] == "WEEKLY"
        assert vrecurr["BYDAY"] == ["MO", "WE"]
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=MO,WE"
        assert len(vrecurr.keys()) == 2 
Example #27
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_weekly_tue(self):
        """Repeat every week on Tuesday."""
        vrecurr = utils.build_rrule(freq="WEEKLY", byday="TU")
        assert vrecurr["FREQ"] == "WEEKLY"
        assert vrecurr["BYDAY"] == "TU"
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY;BYDAY=TU"
        assert len(vrecurr.keys()) == 2 
Example #28
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_week(self):
        """Repeat every week."""
        vrecurr = utils.build_rrule(freq="WEEKLY")
        assert vrecurr["FREQ"] == "WEEKLY"
        vRecur(vrecurr).to_ical().decode() == "FREQ=WEEKLY"
        assert len(vrecurr.keys()) == 1 
Example #29
Source File: funactionuorille.py    From linkedevents with MIT License 5 votes vote down vote up
def _create_recurring_event_dates(self, start_date: datetime, end_date: datetime, weekdays: list):
        converted_days = [DAY_MAP[i] for i in weekdays]
        return list(
            rrule(WEEKLY, byweekday=converted_days, dtstart=start_date, until=end_date)
        )