Python dateutil.relativedelta 模块,MO 实例源码

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

项目: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)
项目:flik    作者:rsteube    | 项目源码 | 文件源码
def parse(raw_date):
    weekday = {
        'monday': MO(-1),
        'tuesday': TU(-1),
        'wednesday': WE(-1),
        'thursday': TH(-1),
        'friday': FR(-1),
        'saturday': SA(-1),
        'sunday': SU(-1),
    }
    if raw_date == 'today':
        date = datetime.now().date()
    elif raw_date == 'yesterday':
        date = datetime.now().date() - relativedelta(days=1)
    elif raw_date in weekday:
        date = datetime.now().date() + relativedelta(weekday=weekday[raw_date])
    elif re.match('\d{4}-w\d{2}', raw_date) is not None:
        fromDate = datetime.strptime(raw_date + '-1', "%Y-W%W-%w").date()
        toDate = fromDate + relativedelta(days=7)
        return fromDate, toDate
    else:
        date = datetime.strptime(raw_date, '%Y-%m-%d')
    toDate = date + relativedelta(days=1)
    return date, toDate
项目:lighthouse    作者:dstl    | 项目源码 | 文件源码
def usage_this_week(self):
        """ All usage since midnight on Monday """
        today = timezone.now().replace(hour=0, minute=0, second=0)
        last_monday = today + relativedelta(weekday=MO(-1))
        return self.usage.filter(start__gt=last_monday).count()
项目:Dshield    作者:ywjt    | 项目源码 | 文件源码
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)
项目:smarthome    作者:smarthomeNG    | 项目源码 | 文件源码
def _day_range(self, days):
        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 occurence
            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