當前位置: 首頁>>代碼示例>>Python>>正文


Python rrule.MONTHLY屬性代碼示例

本文整理匯總了Python中dateutil.rrule.MONTHLY屬性的典型用法代碼示例。如果您正苦於以下問題:Python rrule.MONTHLY屬性的具體用法?Python rrule.MONTHLY怎麽用?Python rrule.MONTHLY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在dateutil.rrule的用法示例。


在下文中一共展示了rrule.MONTHLY屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: previous_months_iterator

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def previous_months_iterator(month_for, months_back):
    '''Iterator returns a year,month tuple for n months including the month_for

    month_for is either a date, datetime, or tuple with year and month
    months back is the number of months to iterate

    includes the month_for
    '''

    if isinstance(month_for, tuple):
        # TODO make sure we've got just two values in the tuple
        month_for = datetime.date(year=month_for[0], month=month_for[1], day=1)
    if isinstance(month_for, (datetime.datetime, datetime.date)):
        start_month = month_for - relativedelta(months=months_back)

    for dt in rrule(freq=MONTHLY, dtstart=start_month, until=month_for):
        last_day_of_month = days_in_month(month_for=dt)
        yield (dt.year, dt.month, last_day_of_month) 
開發者ID:appsembler,項目名稱:figures,代碼行數:20,代碼來源:helpers.py

示例2: backfill_monthly_metrics_for_site

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def backfill_monthly_metrics_for_site(site, overwrite=False):
    """Backfill all historical site metrics for the specified site
    """
    site_sm = get_student_modules_for_site(site)
    if not site_sm:
        return None

    first_created = site_sm.order_by('created').first().created

    start_month = datetime(year=first_created.year,
                           month=first_created.month,
                           day=1,
                           tzinfo=utc)
    last_month = datetime.utcnow().replace(tzinfo=utc) - relativedelta(months=1)
    backfilled = []
    for dt in rrule(freq=MONTHLY, dtstart=start_month, until=last_month):
        obj, created = fill_month(site=site,
                                  month_for=dt,
                                  student_modules=site_sm,
                                  overwrite=overwrite)
        backfilled.append(dict(obj=obj, created=created, dt=dt))

    return backfilled 
開發者ID:appsembler,項目名稱:figures,代碼行數:25,代碼來源:backfill.py

示例3: testRRuleAll

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
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) 
開發者ID:MediaBrowser,項目名稱:plugin.video.emby,代碼行數:21,代碼來源:test_imports.py

示例4: month_blocks

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def month_blocks(start, end):
    """
    Create pairs of start and end with max a month in between, to deal with usage restrictions on the API

    Parameters
    ----------
    start : dt.datetime | pd.Timestamp
    end : dt.datetime | pd.Timestamp

    Returns
    -------
    ((pd.Timestamp, pd.Timestamp))
    """
    rule = rrule.MONTHLY

    res = []
    for day in rrule.rrule(rule, dtstart=start, until=end):
        res.append(pd.Timestamp(day))
    res.append(end)
    res = sorted(set(res))
    res = pairwise(res)
    return res 
開發者ID:EnergieID,項目名稱:entsoe-py,代碼行數:24,代碼來源:misc.py

示例5: _getWhen

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
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 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:22,代碼來源:recurrence.py

示例6: test_sync_file_fail_no_file

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_sync_file_fail_no_file(self, mock_boto3):
        """Test syncing a file from one S3 bucket to another fails due to no matching files."""
        source_bucket_name = fake.slug()
        destination_bucket_name = fake.slug()
        schema_name = self.schema

        start_date = date(2019, 1, 1)
        end_date = date(2019, 3, 1)
        date_range = (start_date, end_date)

        end_date = end_date - timedelta(days=1)
        days = rrule(DAILY, dtstart=start_date, until=end_date)
        months = rrule(MONTHLY, dtstart=start_date, until=end_date)

        self.assertNotEqual(source_bucket_name, destination_bucket_name)

        mock_resource = mock_boto3.resource
        mock_buckets = mock_resource.return_value.Bucket
        mock_filter = mock_buckets.return_value.objects.filter
        mock_filter.return_value = ()
        mock_destination_object = mock_buckets.return_value.Object
        mock_copy_from = mock_destination_object.return_value.copy_from

        syncer = AwsS3Syncer(source_bucket_name)
        syncer.sync_bucket(schema_name, destination_bucket_name, date_range)

        mock_resource.assert_called_with("s3", settings.S3_REGION)
        mock_buckets.assert_any_call(source_bucket_name)
        mock_buckets.assert_any_call(destination_bucket_name)

        expected_filter_calls = self.get_expected_filter_calls(schema_name, days, months)
        mock_filter.assert_has_calls(expected_filter_calls, any_order=True)
        self.assertEqual(len(mock_filter.call_args_list), len(expected_filter_calls))

        mock_destination_object.assert_not_called()
        mock_copy_from.assert_not_called() 
開發者ID:project-koku,項目名稱:koku,代碼行數:38,代碼來源:tests_syncer.py

示例7: populate_monthly_cost

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def populate_monthly_cost(self, cost_type, rate_type, rate, start_date, end_date, cluster_id, cluster_alias):
        """
        Populate the monthly cost of a customer.

        Right now this is just the node/month cost. Calculated from
        node_cost * number_unique_nodes.

        args:
            node_cost (Decimal): The node cost per month
            start_date (datetime, str): The start_date to calculate monthly_cost.
            end_date (datetime, str): The end_date to calculate monthly_cost.

        """
        if isinstance(start_date, str):
            start_date = parse(start_date).date()
        if isinstance(end_date, str):
            end_date = parse(end_date).date()

        # usage_start, usage_end are date types
        first_month = datetime.datetime(*start_date.replace(day=1).timetuple()[:3]).replace(tzinfo=pytz.UTC)
        end_date = datetime.datetime(*end_date.timetuple()[:3]).replace(hour=23, minute=59, second=59, tzinfo=pytz.UTC)

        # Calculate monthly cost for each month from start date to end date
        for curr_month in rrule(freq=MONTHLY, until=end_date, dtstart=first_month):
            first_curr_month, first_next_month = month_date_range_tuple(curr_month)
            LOG.info("Populating monthly cost from %s to %s.", first_curr_month, first_next_month)
            if cost_type == "Node":
                if rate is None:
                    self.remove_monthly_cost(first_curr_month, first_next_month, cluster_id, cost_type)
                else:
                    self.upsert_monthly_node_cost_line_item(
                        first_curr_month, first_next_month, cluster_id, cluster_alias, rate_type, rate
                    )
            elif cost_type == "Cluster":
                if rate is None:
                    self.remove_monthly_cost(first_curr_month, first_next_month, cluster_id, cost_type)
                else:
                    self.upsert_monthly_cluster_cost_line_item(
                        first_curr_month, first_next_month, cluster_id, cluster_alias, rate_type, rate
                    ) 
開發者ID:project-koku,項目名稱:koku,代碼行數:42,代碼來源:ocp_report_db_accessor.py

示例8: test_every_month

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_every_month(self):
        """Repeat every month."""
        vrecurr = utils.build_rrule(freq="MONTHLY")
        assert vrecurr["FREQ"] == "MONTHLY"
        vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY"
        assert len(vrecurr.keys()) == 1 
開發者ID:jazzband,項目名稱:django-ical,代碼行數:8,代碼來源:test_recurrence.py

示例9: test_every_6_months

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_every_6_months(self):
        """Repeat very 6 months."""
        vrecurr = utils.build_rrule(interval=6, freq="MONTHLY")
        assert vrecurr["FREQ"] == "MONTHLY"
        assert vrecurr["INTERVAL"] == 6
        vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;INTERVAL=6"
        assert len(vrecurr.keys()) == 2 
開發者ID:jazzband,項目名稱:django-ical,代碼行數:9,代碼來源:test_recurrence.py

示例10: test_every_month_on_the_4th

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_every_month_on_the_4th(self):
        """Repeat every month on the 4th."""
        vrecurr = utils.build_rrule(freq="MONTHLY", bymonthday=4)
        assert vrecurr["FREQ"] == "MONTHLY"
        assert vrecurr["BYMONTHDAY"] == 4
        vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=4"
        assert len(vrecurr.keys()) == 2 
開發者ID:jazzband,項目名稱:django-ical,代碼行數:9,代碼來源:test_recurrence.py

示例11: test_every_month_on_the_4th_last

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_every_month_on_the_4th_last(self):
        """Repeat every month on the 4th last."""
        vrecurr = utils.build_rrule(freq="MONTHLY", bymonthday=-4)
        assert vrecurr["FREQ"] == "MONTHLY"
        assert vrecurr["BYMONTHDAY"] == -4
        vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=-4"
        assert len(vrecurr.keys()) == 2 
開發者ID:jazzband,項目名稱:django-ical,代碼行數:9,代碼來源:test_recurrence.py

示例12: test_ever_month_3rd_tu

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_ever_month_3rd_tu(self):
        """Repeat every month on the 3rd Tuesday."""
        vrecurr = utils.build_rrule(freq="MONTHLY", byday="+3TU")
        assert vrecurr["FREQ"] == "MONTHLY"
        assert vrecurr["BYDAY"] == "+3TU"
        vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=+3TU"
        assert len(vrecurr.keys()) == 2 
開發者ID:jazzband,項目名稱:django-ical,代碼行數:9,代碼來源:test_recurrence.py

示例13: test_ever_month_last_mo

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_ever_month_last_mo(self):
        """Repeat every month on the last Monday."""
        vrecurr = utils.build_rrule(freq="MONTHLY", byday="-1MO")
        assert vrecurr["FREQ"] == "MONTHLY"
        assert vrecurr["BYDAY"] == "-1MO"
        vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYDAY=-1MO"
        assert len(vrecurr.keys()) == 2 
開發者ID:jazzband,項目名稱:django-ical,代碼行數:9,代碼來源:test_recurrence.py

示例14: test_every_month_last_working_day

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_every_month_last_working_day(self):
        """Repeat the last working day of each month."""
        vrecurr = utils.build_rrule(
            freq="MONTHLY", byday=["MO", "TU", "WE", "TH", "FR"], bysetpos=-1
        )
        assert vrecurr["FREQ"] == "MONTHLY"
        assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR"]
        assert vrecurr["BYSETPOS"] == -1
        vRecur(
            vrecurr
        ).to_ical().decode() == "FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1"
        assert len(vrecurr.keys()) == 3 
開發者ID:jazzband,項目名稱:django-ical,代碼行數:14,代碼來源:test_recurrence.py

示例15: test_ever_month_last_day

# 需要導入模塊: from dateutil import rrule [as 別名]
# 或者: from dateutil.rrule import MONTHLY [as 別名]
def test_ever_month_last_day(self):
        """Repeat the last day of each month."""
        vrecurr = utils.build_rrule(freq="MONTHLY", bymonthday=-1)
        assert vrecurr["FREQ"] == "MONTHLY"
        assert vrecurr["BYMONTHDAY"] == -1
        vRecur(vrecurr).to_ical().decode() == "FREQ=MONTHLY;BYMONTHDAY=-1"
        assert len(vrecurr.keys()) == 2 
開發者ID:jazzband,項目名稱:django-ical,代碼行數:9,代碼來源:test_recurrence.py


注:本文中的dateutil.rrule.MONTHLY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。