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


Python calendar.weekday方法代码示例

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


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

示例1: test_W_wildcard

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def test_W_wildcard(self):
        years = [2016, 2017]  # leap and normal year

        for year in years:
            for month in range(1, 13):
                _, days = calendar.monthrange(year, month)

                for day in range(1, days):
                    weekday = calendar.weekday(year, month, day)
                    result = day
                    if weekday == 5:
                        result = day - 1 if day > 1 else day + 2
                    elif weekday == 6:
                        result = day + 1 if day < days else day - 2

                    self.assertEqual(MonthdaySetBuilder(year, month).build(str(day) + "W"), {result}) 
开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:18,代码来源:test_monthday_setbuilder.py

示例2: process_schedules

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def process_schedules(self, export_map, now, startup=False):
        Logger.debug('now: %s, startup: %s' % (Utils.str(now), Utils.str(startup)))
        export_list = []
        if startup:
            export_list.extend(Utils.get_safe_value(export_map, self._startup_type, []))
        else:
            at = '%02d:%02d' % (now.hour, now.minute,)
            Logger.debug('at: %s' % Utils.str(at))
            daily_list = Utils.get_safe_value(export_map, Utils.str(ExportScheduleDialog._daily_type) + at, [])
            export_list.extend(daily_list)
            Logger.debug('daily_list: %s' % Utils.str(daily_list))
            weekday = now.weekday() + 11
            weekday_list = Utils.get_safe_value(export_map, Utils.str(weekday) + at, [])
            export_list.extend(weekday_list)
            Logger.debug('weekday_list: %s' % Utils.str(weekday_list))
        Logger.debug('export_list: %s' % Utils.str(export_list) )
        for export in export_list:
            self.run_export(export) 
开发者ID:cguZZman,项目名称:script.module.clouddrive.common,代码行数:20,代码来源:export.py

示例3: is_valid_date

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def is_valid_date(given_date):
    """
    Given a date string this function checks if the date is in the future
    """

    given_date = given_date.split("/")
    current_date = get_current_date().split("/")

    given_day = int(given_date[1])
    given_month = int(given_date[0])
    given_year = int(given_date[2])

    current_day = int(current_date[1])
    current_month = int(current_date[0])
    current_year = int(current_date[2])

    try:
        calendar.weekday(given_year, given_month, given_day)
    except ValueError:
        return False

    return (
        (given_year == current_year and given_month == current_month and given_day > current_day) or
        (given_year == current_year and given_month > current_month) or
        (given_year > current_year)) 
开发者ID:areebbeigh,项目名称:hacker-scripts,代码行数:27,代码来源:hs-schedule.py

示例4: next_monthday_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def next_monthday_weekday(cls, tmp_dict, timer_params):
        """
        set next monthday && weekday
        """
        plus = 1
        while True:
            tmp_dict['monthday'] += plus
            if plus == 0:
                plus = 1
            if all([
                tmp_dict['monthday'] in timer_params['monthday'],
                cls.check_monthday_weekday(tmp_dict, timer_params)
            ]):
                tmp_dict['hour'] = timer_params['hour'][0]
                tmp_dict['minute'] = timer_params['hour'][0]
                break
            else:
                if tmp_dict['monthday'] > 31:
                    cls.next_month(tmp_dict, timer_params)
                    plus = 0 
开发者ID:baidu,项目名称:CUP,代码行数:22,代码来源:executor.py

示例5: __init__

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def __init__(self, *args, **keys):
        self._spec = {}

        max_priority = min(x.time_tuple_index for x in self._units.values())

        for key, arg in dict(*args, **keys).iteritems():
            if key not in self._units:
                raise TypeError("unexpected unit {0!r}".format(key))

            unit = self._units[key]
            max_priority = max(max_priority, unit.time_tuple_index)
            rangeobj = self._coerce(arg)
            self._spec[key] = unit.resolve(rangeobj)

        for key, unit in self._units.iteritems():
            if key in self._spec:
                continue

            if max_priority >= unit.time_tuple_index:
                self._spec[key] = unit.resolve(any())
            else:
                self._spec[key] = unit.resolve(value(unit.min))

        # Special case: If both day or weekday is limited, then use OR instead of AND.
        if self._is_any("day"):
            self._spec["day"] = self._units["day"].resolve(empty())
        elif self._is_any("weekday"):
            self._spec["weekday"] = self._units["weekday"].resolve(empty())
        self._spec["day"] = _ResolvedOr(self._spec.pop("day"), self._spec.pop("weekday")) 
开发者ID:abusesa,项目名称:abusehelper,代码行数:31,代码来源:cron.py

示例6: amod

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def amod(a, b):
    '''Modulus function which returns numerator if modulus is zero'''
    modded = int(a % b)
    return b if modded == 0 else modded


# Sane people of the world, use calendar.weekday! 
开发者ID:fitnr,项目名称:convertdate,代码行数:9,代码来源:utils.py

示例7: weekday_before

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def weekday_before(weekday, jd):
    return jd - jwday(jd - weekday)


# @param weekday      Day of week desired, 0 = Monday
# @param jd           Julian date to begin search
# @param direction    1 = next weekday, -1 = last weekday
# @param offset       Offset from jd to begin search 
开发者ID:fitnr,项目名称:convertdate,代码行数:10,代码来源:utils.py

示例8: search_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def search_weekday(weekday, jd, direction, offset):
    '''Determine the Julian date for the next or previous weekday'''
    return weekday_before(weekday, jd + (direction * offset))


#  Utility weekday functions, just wrappers for search_weekday 
开发者ID:fitnr,项目名称:convertdate,代码行数:8,代码来源:utils.py

示例9: nearest_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def nearest_weekday(weekday, jd):
    return search_weekday(weekday, jd, 1, 3) 
开发者ID:fitnr,项目名称:convertdate,代码行数:4,代码来源:utils.py

示例10: next_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def next_weekday(weekday, jd):
    return search_weekday(weekday, jd, 1, 7) 
开发者ID:fitnr,项目名称:convertdate,代码行数:4,代码来源:utils.py

示例11: previous_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def previous_weekday(weekday, jd):
    return search_weekday(weekday, jd, -1, 1) 
开发者ID:fitnr,项目名称:convertdate,代码行数:4,代码来源:utils.py

示例12: previous_or_current_weekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def previous_or_current_weekday(weekday, jd):
    return search_weekday(weekday, jd, 1, 0) 
开发者ID:fitnr,项目名称:convertdate,代码行数:4,代码来源:utils.py

示例13: n_weeks

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def n_weeks(weekday, jd, nthweek):
    j = 7 * nthweek

    if nthweek > 0:
        j += previous_weekday(weekday, jd)
    else:
        j += next_weekday(weekday, jd)

    return j 
开发者ID:fitnr,项目名称:convertdate,代码行数:11,代码来源:utils.py

示例14: nth_day_of_month

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def nth_day_of_month(n, weekday, month, year):
    """
    Return (year, month, day) tuple that represents nth weekday of month in year.
    If n==0, returns last weekday of month. Weekdays: Monday=0
    """
    if not 0 <= n <= 5:
        raise IndexError("Nth day of month must be 0-5. Received: {}".format(n))

    if not 0 <= weekday <= 6:
        raise IndexError("Weekday must be 0-6")

    firstday, daysinmonth = calendar.monthrange(year, month)

    # Get first WEEKDAY of month
    first_weekday_of_kind = 1 + (weekday - firstday) % 7

    if n == 0:
        # find last weekday of kind, which is 5 if these conditions are met, else 4
        if first_weekday_of_kind in [1, 2, 3] and first_weekday_of_kind + 28 <= daysinmonth:
            n = 5
        else:
            n = 4

    day = first_weekday_of_kind + ((n - 1) * 7)

    if day > daysinmonth:
        raise IndexError("No {}th day of month {}".format(n, month))

    return (year, month, day) 
开发者ID:fitnr,项目名称:convertdate,代码行数:31,代码来源:utils.py

示例15: independence_day

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import weekday [as 别名]
def independence_day(year, observed=None):
    '''July 4th'''
    day = 4

    if observed:
        if calendar.weekday(year, JUL, 4) == SAT:
            day = 3

        if calendar.weekday(year, JUL, 4) == SUN:
            day = 5

    return (year, JUL, day) 
开发者ID:fitnr,项目名称:convertdate,代码行数:14,代码来源:holidays.py


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