Python dateutil.rrule 模块,MONTHLY 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用dateutil.rrule.MONTHLY

项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
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)
项目:vobject    作者:eventable    | 项目源码 | 文件源码
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)
项目:facebook-message-analysis    作者:szheng17    | 项目源码 | 文件源码
def get_month_to_message_statistic(self, message_statistic):
        """
        Maps each month between the month of the first message and the month of
        the last message, inclusive, to the sum of the values of a message
        statistic over all messages from that month. 

        Args:
            message_statistic: A function mapping a Message object to an int or
                a float.

        Returns:
            month_to_message_statistic: A dict mapping a string of the form
                'YYYY-MM' representing a month between the month of the first
                message and the month of the last message to the sum of the
                values of message_statistic over all messages in self.messages
                from that month.
        """
        start_dt = self.messages[0].timestamp
        end_dt = self.messages[-1].timestamp
        start_date_month_start = datetime(start_dt.year, start_dt.month, 1)
        end_date_month_start = datetime(end_dt.year, end_dt.month, 1)
        dt_month_range = rrule(MONTHLY, dtstart=start_date_month_start,
                               until=end_date_month_start)
        month_range = [dt.date() for dt in dt_month_range]
        month_to_message_statistic = {dt.strftime(self.MONTH_FORMAT): 0 for dt in month_range}
        for message in self.messages:
            month_str = message.timestamp.strftime(self.MONTH_FORMAT)
            month_to_message_statistic[month_str] += message_statistic(message)
        return month_to_message_statistic
项目:zipline-chinese    作者:zhanghan1990    | 项目源码 | 文件源码
def get_early_closes(start, end):
    # TSX closed at 1:00 PM on december 24th.

    start = canonicalize_datetime(start)
    end = canonicalize_datetime(end)

    start = max(start, datetime(1993, 1, 1, tzinfo=pytz.utc))
    end = max(end, datetime(1993, 1, 1, tzinfo=pytz.utc))

    # Not included here are early closes prior to 1993
    # or unplanned early closes

    early_close_rules = []

    christmas_eve = rrule.rrule(
        rrule.MONTHLY,
        bymonth=12,
        bymonthday=24,
        byweekday=(rrule.MO, rrule.TU, rrule.WE, rrule.TH, rrule.FR),
        cache=True,
        dtstart=start,
        until=end
    )
    early_close_rules.append(christmas_eve)

    early_close_ruleset = rrule.rruleset()

    for rule in early_close_rules:
        early_close_ruleset.rrule(rule)
    early_closes = early_close_ruleset.between(start, end, inc=True)

    early_closes.sort()
    return pd.DatetimeIndex(early_closes)
项目:wagtail_room_booking    作者:Tamriel    | 项目源码 | 文件源码
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]