Python dateutil.relativedelta.MO Examples
The following are 16
code examples of dateutil.relativedelta.MO().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dateutil.relativedelta
, or try the search function
.
Example #1
Source File: test_imports.py From plugin.video.emby with GNU General Public License v3.0 | 7 votes |
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)
Example #2
Source File: test_relativedelta.py From plugin.video.emby with GNU General Public License v3.0 | 6 votes |
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)
Example #3
Source File: scheduler.py From smarthome with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: austria.py From python-holidays with MIT License | 6 votes |
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"
Example #5
Source File: test_imports.py From bazarr with GNU General Public License v3.0 | 6 votes |
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)
Example #6
Source File: test_relativedelta.py From plugin.video.emby with GNU General Public License v3.0 | 5 votes |
def test15thISOYearWeek(self): self.assertEqual(date(2003, 1, 1) + relativedelta(day=4, weeks=+14, weekday=MO(-1)), date(2003, 4, 7))
Example #7
Source File: test_imports.py From plugin.video.emby with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: dominican_republic.py From python-holidays with MIT License | 5 votes |
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
Example #9
Source File: denmark.py From python-holidays with MIT License | 5 votes |
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"
Example #10
Source File: luxembourg.py From python-holidays with MIT License | 5 votes |
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"
Example #11
Source File: kenya.py From python-holidays with MIT License | 5 votes |
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"
Example #12
Source File: views.py From moolah with GNU General Public License v3.0 | 5 votes |
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'] })
Example #13
Source File: base.py From did with GNU General Public License v2.0 | 5 votes |
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)
Example #14
Source File: base.py From did with GNU General Public License v2.0 | 5 votes |
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)
Example #15
Source File: manager.py From django-pg-partitioning with MIT License | 5 votes |
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
Example #16
Source File: test_imports.py From bazarr with GNU General Public License v3.0 | 5 votes |
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)