本文整理汇总了Python中dateutil.relativedelta.MO属性的典型用法代码示例。如果您正苦于以下问题:Python relativedelta.MO属性的具体用法?Python relativedelta.MO怎么用?Python relativedelta.MO使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类dateutil.relativedelta
的用法示例。
在下文中一共展示了relativedelta.MO属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testInequalityWeekdays
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def testInequalityWeekdays(self):
# Different weekdays
no_wday = relativedelta(year=1997, month=4)
wday_mo_1 = relativedelta(year=1997, month=4, weekday=MO(+1))
wday_mo_2 = relativedelta(year=1997, month=4, weekday=MO(+2))
wday_tu = relativedelta(year=1997, month=4, weekday=TU)
self.assertTrue(wday_mo_1 == wday_mo_1)
self.assertFalse(no_wday == wday_mo_1)
self.assertFalse(wday_mo_1 == no_wday)
self.assertFalse(wday_mo_1 == wday_mo_2)
self.assertFalse(wday_mo_2 == wday_mo_1)
self.assertFalse(wday_mo_1 == wday_tu)
self.assertFalse(wday_tu == wday_mo_1)
示例2: testRRuleAll
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [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)
示例3: _day_range
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def _day_range(self, days):
"""
inspect a given string with days given as integer numbers separated by ","
:param days:
:return: an array with strings containing the days of month
"""
now = datetime.date.today()
wdays = [MO, TU, WE, TH, FR, SA, SU]
result = []
for day in days.split(','):
wday = wdays[int(day)]
# add next weekday occurrence
day = now + dateutil.relativedelta.relativedelta(weekday=wday)
result.append(day.strftime("%d"))
# safety add-on if weekday equals todays weekday
day = now + dateutil.relativedelta.relativedelta(weekday=wday(+2))
result.append(day.strftime("%d"))
return result
示例4: _populate
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def _populate(self, year):
# public holidays
self[date(year, JAN, 1)] = "Neujahr"
self[date(year, JAN, 6)] = "Heilige Drei Könige"
self[easter(year) + rd(weekday=MO)] = "Ostermontag"
self[date(year, MAY, 1)] = "Staatsfeiertag"
self[easter(year) + rd(days=39)] = "Christi Himmelfahrt"
self[easter(year) + rd(days=50)] = "Pfingstmontag"
self[easter(year) + rd(days=60)] = "Fronleichnam"
self[date(year, AUG, 15)] = "Mariä Himmelfahrt"
if 1919 <= year <= 1934:
self[date(year, NOV, 12)] = "Nationalfeiertag"
if year >= 1967:
self[date(year, OCT, 26)] = "Nationalfeiertag"
self[date(year, NOV, 1)] = "Allerheiligen"
self[date(year, DEC, 8)] = "Mariä Empfängnis"
self[date(year, DEC, 25)] = "Christtag"
self[date(year, DEC, 26)] = "Stefanitag"
示例5: test15thISOYearWeek
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def test15thISOYearWeek(self):
self.assertEqual(date(2003, 1, 1) +
relativedelta(day=4, weeks=+14, weekday=MO(-1)),
date(2003, 4, 7))
示例6: testRelativeDeltaAll
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def testRelativeDeltaAll(self):
from dateutil.relativedelta import relativedelta
from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU
for var in (relativedelta, MO, TU, WE, TH, FR, SA, SU):
self.assertIsNot(var, None)
# In the public interface but not in all
from dateutil.relativedelta import weekday
self.assertIsNot(weekday, None)
示例7: __change_day_by_law
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def __change_day_by_law(holiday, latest_days=(3, 4)):
# Law No. 139-97 - Holidays Dominican Republic - Jun 27, 1997
if holiday >= date(1997, 6, 27):
if holiday.weekday() in [1, 2]:
holiday -= rd(weekday=MO(-1))
elif holiday.weekday() in latest_days:
holiday += rd(weekday=MO(1))
return holiday
示例8: _populate
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def _populate(self, year):
# Public holidays
self[date(year, JAN, 1)] = "Nytårsdag"
self[easter(year) + rd(weekday=SU(-2))] = "Palmesøndag"
self[easter(year) + rd(weekday=TH(-1))] = "Skærtorsdag"
self[easter(year) + rd(weekday=FR(-1))] = "Langfredag"
self[easter(year)] = "Påskedag"
self[easter(year) + rd(weekday=MO)] = "Anden påskedag"
self[easter(year) + rd(weekday=FR(+4))] = "Store bededag"
self[easter(year) + rd(days=39)] = "Kristi himmelfartsdag"
self[easter(year) + rd(days=49)] = "Pinsedag"
self[easter(year) + rd(days=50)] = "Anden pinsedag"
self[date(year, DEC, 25)] = "Juledag"
self[date(year, DEC, 26)] = "Anden juledag"
示例9: _populate
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def _populate(self, year):
# Public holidays
self[date(year, JAN, 1)] = "Neijoerschdag"
self[easter(year) + rd(weekday=MO)] = "Ouschterméindeg"
self[date(year, MAY, 1)] = "Dag vun der Aarbecht"
if year >= 2019:
# Europe Day: not in legislation yet, but introduced starting 2019
self[date(year, MAY, 9)] = "Europadag"
self[easter(year) + rd(days=39)] = "Christi Himmelfaart"
self[easter(year) + rd(days=50)] = "Péngschtméindeg"
self[date(year, JUN, 23)] = "Nationalfeierdag"
self[date(year, AUG, 15)] = "Léiffrawëschdag"
self[date(year, NOV, 1)] = "Allerhellgen"
self[date(year, DEC, 25)] = "Chrëschtdag"
self[date(year, DEC, 26)] = "Stiefesdag"
示例10: _populate
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def _populate(self, year):
# Public holidays
self[date(year, JAN, 1)] = "New Year's Day"
self[date(year, MAY, 1)] = "Labour Day"
self[date(year, JUN, 1)] = "Madaraka Day"
self[date(year, OCT, 20)] = "Mashujaa Day"
self[date(year, DEC, 12)] = "Jamhuri (Independence) Day"
self[date(year, DEC, 25)] = "Christmas Day"
self[date(year, DEC, 26)] = "Boxing Day"
for k, v in list(self.items()):
if self.observed and k.weekday() == SUN:
self[k + rd(days=1)] = v + " (Observed)"
self[easter(year) - rd(weekday=FR(-1))] = "Good Friday"
self[easter(year) + rd(weekday=MO(+1))] = "Easter Monday"
示例11: week_breakdown
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def week_breakdown(self, *args, **kwargs):
today = timezone.now()
def get_week_dates(weeks=-1):
monday = today + relativedelta(weekday=MO(weeks))
return [
monday + timezone.timedelta(days=n)
for n in range(7)
]
t = Transaction.objects.without_allowance()
labels = [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
]
this_week = [
t.date(d).total()
for d in get_week_dates()
]
last_week = [
t.date(d).total()
for d in get_week_dates(-2)
]
return Response({
'labels': labels,
'data': [this_week, last_week],
'series': ['This Week', 'Last Week']
})
示例12: this_week
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def this_week():
""" Return start and end date of the current week. """
since = TODAY + delta(weekday=MONDAY(-1))
until = since + delta(weeks=1)
return Date(since), Date(until)
示例13: last_week
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def last_week():
""" Return start and end date of the last week. """
since = TODAY + delta(weekday=MONDAY(-2))
until = since + delta(weeks=1)
return Date(since), Date(until)
示例14: create_partition
# 需要导入模块: from dateutil import relativedelta [as 别名]
# 或者: from dateutil.relativedelta import MO [as 别名]
def create_partition(self, max_days_to_next_partition: int = 1) -> None:
"""The partition of the next cycle is created according to the configuration.
After modifying the period field, the new period will take effect the next time.
The start time of the new partition is the end time of the previous partition table,
or the start time of the current archive period when no partition exists.
For example:
the current time is June 5, 2018, and the archiving period is one year,
then the start time of the first partition is 00:00:00 on January 1, 2018.
Parameters:
max_days_to_next_partition(int):
If numbers of days remained in current partition is greater than ``max_days_to_next_partition``, no new partitions will be created.
"""
while True:
if max_days_to_next_partition > 0 and self.latest and timezone.now() < (self.latest.end - relativedelta(days=max_days_to_next_partition)):
return
partition_timezone = getattr(settings, "PARTITION_TIMEZONE", None)
if partition_timezone:
partition_timezone = pytz.timezone(partition_timezone)
date_start = timezone.localtime(self.latest.end if self.latest else None, timezone=partition_timezone)
initial = not bool(self.latest)
date_start, date_end = {
PeriodType.Day: self._get_period_bound(date_start, initial, days=+1),
PeriodType.Week: self._get_period_bound(date_start, initial, is_week=True, days=+1, weekday=MO),
PeriodType.Month: self._get_period_bound(date_start, initial, addition_zeros=dict(day=1), months=+1),
PeriodType.Year: self._get_period_bound(date_start, initial, addition_zeros=dict(month=1, day=1), years=+1),
}[self.config.period]()
partition_table_name = "_".join((self.model._meta.db_table, date_start.strftime(DT_FORMAT), date_end.strftime(DT_FORMAT)))
PartitionLog.objects.create(config=self.config, table_name=partition_table_name, start=date_start, end=date_end)
if not max_days_to_next_partition > 0:
return