当前位置: 首页>>代码示例>>Python>>正文


Python date.weekday方法代码示例

本文整理汇总了Python中datetime.date.weekday方法的典型用法代码示例。如果您正苦于以下问题:Python date.weekday方法的具体用法?Python date.weekday怎么用?Python date.weekday使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在datetime.date的用法示例。


在下文中一共展示了date.weekday方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_week

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import weekday [as 别名]
def format_week(self, char, num):
        if char.islower(): # week of year
            day_of_year = self.get_day_of_year()
            week = self.get_week_number(day_of_year)
            if week == 0:
                date = self.value - timedelta(days=day_of_year)
                week = self.get_week_number(self.get_day_of_year(date),
                                            date.weekday())
            return self.format(week, num)
        else: # week of month
            week = self.get_week_number(self.value.day)
            if week == 0:
                date = self.value - timedelta(days=self.value.day)
                week = self.get_week_number(date.day, date.weekday())
                pass
            return '%d' % week 
开发者ID:Schibum,项目名称:sndlatr,代码行数:18,代码来源:dates.py

示例2: format_weekday

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import weekday [as 别名]
def format_weekday(self, char, num):
        if num < 3:
            if char.islower():
                value = 7 - self.locale.first_week_day + self.value.weekday()
                return self.format(value % 7 + 1, num)
            num = 3
        weekday = self.value.weekday()
        width = {3: 'abbreviated', 4: 'wide', 5: 'narrow'}[num]
        context = {3: 'format', 4: 'format', 5: 'stand-alone'}[num]
        return get_day_names(width, context, self.locale)[weekday] 
开发者ID:Schibum,项目名称:sndlatr,代码行数:12,代码来源:dates.py

示例3: get_week_number

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import weekday [as 别名]
def get_week_number(self, day_of_period, day_of_week=None):
        """Return the number of the week of a day within a period. This may be
        the week number in a year or the week number in a month.

        Usually this will return a value equal to or greater than 1, but if the
        first week of the period is so short that it actually counts as the last
        week of the previous period, this function will return 0.

        >>> format = DateTimeFormat(date(2006, 1, 8), Locale.parse('de_DE'))
        >>> format.get_week_number(6)
        1

        >>> format = DateTimeFormat(date(2006, 1, 8), Locale.parse('en_US'))
        >>> format.get_week_number(6)
        2

        :param day_of_period: the number of the day in the period (usually
                              either the day of month or the day of year)
        :param day_of_week: the week day; if ommitted, the week day of the
                            current date is assumed
        """
        if day_of_week is None:
            day_of_week = self.value.weekday()
        first_day = (day_of_week - self.locale.first_week_day -
                     day_of_period + 1) % 7
        if first_day < 0:
            first_day += 7
        week_number = (day_of_period + first_day - 1) // 7
        if 7 - first_day >= self.locale.min_week_days:
            week_number += 1
        return week_number 
开发者ID:Schibum,项目名称:sndlatr,代码行数:33,代码来源:dates.py

示例4: format_week

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import weekday [as 别名]
def format_week(self, char, num):
        if char.islower():  # week of year
            day_of_year = self.get_day_of_year()
            week = self.get_week_number(day_of_year)
            if week == 0:
                date = self.value - timedelta(days=day_of_year)
                week = self.get_week_number(self.get_day_of_year(date),
                                            date.weekday())
            return self.format(week, num)
        else:  # week of month
            week = self.get_week_number(self.value.day)
            if week == 0:
                date = self.value - timedelta(days=self.value.day)
                week = self.get_week_number(date.day, date.weekday())
            return '%d' % week 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:17,代码来源:dates.py

示例5: format_weekday

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import weekday [as 别名]
def format_weekday(self, char='E', num=4):
        """
        Return weekday from parsed datetime according to format pattern.

        >>> format = DateTimeFormat(date(2016, 2, 28), Locale.parse('en_US'))
        >>> format.format_weekday()
        u'Sunday'

        'E': Day of week - Use one through three letters for the abbreviated day name, four for the full (wide) name,
             five for the narrow name, or six for the short name.
        >>> format.format_weekday('E',2)
        u'Sun'

        'e': Local day of week. Same as E except adds a numeric value that will depend on the local starting day of the
             week, using one or two letters. For this example, Monday is the first day of the week.
        >>> format.format_weekday('e',2)
        '01'

        'c': Stand-Alone local day of week - Use one letter for the local numeric value (same as 'e'), three for the
             abbreviated day name, four for the full (wide) name, five for the narrow name, or six for the short name.
        >>> format.format_weekday('c',1)
        '1'

        :param char: pattern format character ('e','E','c')
        :param num: count of format character

        """
        if num < 3:
            if char.islower():
                value = 7 - self.locale.first_week_day + self.value.weekday()
                return self.format(value % 7 + 1, num)
            num = 3
        weekday = self.value.weekday()
        width = {3: 'abbreviated', 4: 'wide', 5: 'narrow', 6: 'short'}[num]
        if char == 'c':
            context = 'stand-alone'
        else:
            context = 'format'
        return get_day_names(width, context, self.locale)[weekday] 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:41,代码来源:dates.py

示例6: update_date

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import weekday [as 别名]
def update_date(self, date=None, save=False):
        """
        Calculates the date to the next occurence and optionally saves it.
        It uses the usual_month_day if set for setting the correct day in a monthly recurrence
        """
        delta = None
        if not date:
            date = self.date
        if self.interval == self.MONTHLY:
            delta = relativedelta(months=1)
        elif self.interval == self.QUARTERLY:
            delta = relativedelta(months=3)
        elif self.interval == self.BIANNUALLY:
            delta = relativedelta(months=6)
        elif self.interval == self.ANNUALLY:
            delta = relativedelta(years=1)
        elif self.interval == self.WEEKLY:
            delta = relativedelta(weeks=1)
        elif self.interval == self.DAILY:
            delta = relativedelta(days=1)
        else:
            return
        delta *= self.multiplier
        while True:
            date += delta
            if self.usual_month_day > 0 and self.interval not in [self.WEEKLY, self.DAILY]:
                day = self.usual_month_day
                while True:
                    try:
                        date = date.replace(day=day)
                        break
                    except ValueError:
                        day -= 1
                        pass
            if date.weekday() > 4 and self.interval not in [self.WEEKLY, self.DAILY]:
                if self.weekend_handling == self.SKIP:
                    continue
                elif self.weekend_handling == self.NEXT_WEEKDAY:
                    date += relativedelta(days=7 - date.weekday())
                elif self.weekend_handling == self.PREVIOUS_WEEKDAY:
                    date -= relativedelta(days=date.weekday() - 4)
            if save:
                self.date = date
                self.save()
            return date 
开发者ID:agstrike,项目名称:silverstrike,代码行数:47,代码来源:models.py

示例7: check_soc

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import weekday [as 别名]
def check_soc():
    """Retrieve vehicle status and stop or start charging if
    current charging level matches or exceeds specified max level and
    the vehicle is currently charging.
    """
    threading.Timer(60.0, check_soc).start()  # Called every minute

    p = v.get_position()
    position = (p['position']['latitude'], p['position']['longitude'])
    d = int(1000*distance(home,position))
    if (d > 100):
        logger.info("car is "+str(d)+"m from home")
        return

    t = datetime.datetime.now()
    # offpeak: M-F (0-4) 0:00- 7:00, 23:00-23:59
    #          S-S (5-6) 0:00-15:00, 19:00-23:59 
    today = date.weekday(t)
    offpeak = ( (t.hour <  peak[today][0] or t.hour >= peak[today][1]))

    # getting health status forces a status update
    healthstatus = v.get_health_status()
    status = { d['key'] : d['value'] for d in v.get_status()['vehicleStatus'] }

    current_soc = int(status['EV_STATE_OF_CHARGE'])
    charging_status = status['EV_CHARGING_STATUS']
    logger.info("current SoC is "+str(current_soc)+"%"+", offpeak is "+str(offpeak))

    if status['EV_CHARGING_METHOD']  == "WIRED":
        logger.info("car is plugged in")
        logger.info("charging status is "+charging_status)
        if offpeak:
            # allow for SoC to drop a little to avoid restarting too often
            if current_soc < max_soc-1 and charging_status == "PAUSED":
                logger.info("sending start charging request")
                v.charging_start()
            elif current_soc >= max_soc and charging_status == "CHARGING":
                # Stop charging if max SoC is reached
                logger.info("sending stop charging request")
                v.charging_stop()
        elif charging_status == "CHARGING":
            # Stop charging if we are charging during peak
            logger.info("sending stop charging request")
            v.charging_stop()
    else:
        logger.info("car is not plugged in") 
开发者ID:ardevd,项目名称:jlrpy,代码行数:48,代码来源:charge_offpeak.py


注:本文中的datetime.date.weekday方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。