我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用dateutil.rrule.WEEKLY。
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)
def test_timezone_serializing(): """ Serializing with timezones test """ tzs = dateutil.tz.tzical("test_files/timezones.ics") pacific = tzs.get('US/Pacific') cal = base.Component('VCALENDAR') cal.setBehavior(icalendar.VCalendar2_0) ev = cal.add('vevent') ev.add('dtstart').value = datetime.datetime(2005, 10, 12, 9, tzinfo=pacific) evruleset = rruleset() evruleset.rrule(rrule(WEEKLY, interval=2, byweekday=[2,4], until=datetime.datetime(2005, 12, 15, 9))) evruleset.rrule(rrule(MONTHLY, bymonthday=[-1,-5])) evruleset.exdate(datetime.datetime(2005, 10, 14, 9, tzinfo=pacific)) ev.rruleset = evruleset ev.add('duration').value = datetime.timedelta(hours=1) apple = tzs.get('America/Montreal') ev.dtstart.value = datetime.datetime(2005, 10, 12, 9, tzinfo=apple)
def rrule_frequency(self): compatibiliy_dict = { 'DAILY': DAILY, 'MONTHLY': MONTHLY, 'WEEKLY': WEEKLY, 'YEARLY': YEARLY, 'HOURLY': HOURLY, 'MINUTELY': MINUTELY, 'SECONDLY': SECONDLY } return compatibiliy_dict[self.frequency]
def test_recurring_component(self): vevent = RecurringComponent(name='VEVENT') # init self.assertTrue(vevent.isNative) # rruleset should be None at this point. # No rules have been passed or created. self.assertEqual(vevent.rruleset, None) # Now add start and rule for recurring event vevent.add('dtstart').value = datetime.datetime(2005, 1, 19, 9) vevent.add('rrule').value =u"FREQ=WEEKLY;COUNT=2;INTERVAL=2;BYDAY=TU,TH" self.assertEqual( list(vevent.rruleset), [datetime.datetime(2005, 1, 20, 9, 0), datetime.datetime(2005, 2, 1, 9, 0)] ) self.assertEqual( list(vevent.getrruleset(addRDate=True)), [datetime.datetime(2005, 1, 19, 9, 0), datetime.datetime(2005, 1, 20, 9, 0)] ) # Also note that dateutil will expand all-day events (datetime.date values) # to datetime.datetime value with time 0 and no timezone. vevent.dtstart.value = datetime.date(2005,3,18) self.assertEqual( list(vevent.rruleset), [datetime.datetime(2005, 3, 29, 0, 0), datetime.datetime(2005, 3, 31, 0, 0)] ) self.assertEqual( list(vevent.getrruleset(True)), [datetime.datetime(2005, 3, 18, 0, 0), datetime.datetime(2005, 3, 29, 0, 0)] )
def duration_in_weeks(self): weeks = rrule.rrule( rrule.WEEKLY, dtstart=self.start_date, until=self.end_date ) return weeks.count()
def test_recurring_component(self): """ Test recurring events """ vevent = RecurringComponent(name='VEVENT') # init self.assertTrue(vevent.isNative) # rruleset should be None at this point. # No rules have been passed or created. self.assertEqual(vevent.rruleset, None) # Now add start and rule for recurring event vevent.add('dtstart').value = datetime.datetime(2005, 1, 19, 9) vevent.add('rrule').value =u"FREQ=WEEKLY;COUNT=2;INTERVAL=2;BYDAY=TU,TH" self.assertEqual( list(vevent.rruleset), [datetime.datetime(2005, 1, 20, 9, 0), datetime.datetime(2005, 2, 1, 9, 0)] ) self.assertEqual( list(vevent.getrruleset(addRDate=True)), [datetime.datetime(2005, 1, 19, 9, 0), datetime.datetime(2005, 1, 20, 9, 0)] ) # Also note that dateutil will expand all-day events (datetime.date values) # to datetime.datetime value with time 0 and no timezone. vevent.dtstart.value = datetime.date(2005,3,18) self.assertEqual( list(vevent.rruleset), [datetime.datetime(2005, 3, 29, 0, 0), datetime.datetime(2005, 3, 31, 0, 0)] ) self.assertEqual( list(vevent.getrruleset(True)), [datetime.datetime(2005, 3, 18, 0, 0), datetime.datetime(2005, 3, 29, 0, 0)] )