本文整理汇总了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)
示例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
示例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)
示例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
示例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
示例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()
示例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
)
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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