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


Python calendar.mdays方法代码示例

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


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

示例1: timegm

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import mdays [as 别名]
def timegm(year, month, day, hour, minute, second):
    """
    Convert time tuple in GMT to seconds since epoch, GMT
    """
    EPOCH = 1970
    if year < EPOCH:
        raise ValueError("Years prior to %d not supported" % (EPOCH,))
    assert 1 <= month <= 12
    days = 365*(year-EPOCH) + calendar.leapdays(EPOCH, year)
    for i in range(1, month):
        days = days + calendar.mdays[i]
    if month > 2 and calendar.isleap(year):
        days = days + 1
    days = days + day - 1
    hours = days*24 + hour
    minutes = hours*60 + minute
    seconds = minutes*60 + second
    return seconds 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:http.py

示例2: coerce

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import mdays [as 别名]
def coerce(self, args):
        """Return tuple of ints (year, month, day)."""
        if tuple(args) == ("", "", "") and self.allowNone:
            return None

        try:
            year, month, day = map(positiveInt, args)
        except ValueError:
            raise InputError("Invalid date")
        if (month, day) == (2, 29):
            if not calendar.isleap(year):
                raise InputError("%d was not a leap year" % year)
            else:
                return year, month, day
        try:
            mdays = calendar.mdays[month]
        except IndexError:
            raise InputError("Invalid date")
        if day > mdays:
            raise InputError("Invalid date")
        return year, month, day 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:formmethod.py

示例3: _calendar_month_middles

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import mdays [as 别名]
def _calendar_month_middles(year):
    """List of middle day of each month, used by Linke turbidity lookup"""
    # remove mdays[0] since January starts at mdays[1]
    # make local copy of mdays since we need to change
    # February for leap years
    mdays = np.array(calendar.mdays[1:])
    ydays = 365
    # handle leap years
    if calendar.isleap(year):
        mdays[1] = mdays[1] + 1
        ydays = 366
    middles = np.concatenate(
        [[-calendar.mdays[-1] / 2.0],  # Dec last year
         np.cumsum(mdays) - np.array(mdays) / 2.,  # this year
         [ydays + calendar.mdays[1] / 2.0]])  # Jan next year
    return middles 
开发者ID:pvlib,项目名称:pvlib-python,代码行数:18,代码来源:clearsky.py

示例4: coerce

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import mdays [as 别名]
def coerce(self, args):
        """Return tuple of ints (year, month, day)."""
        if tuple(args) == ("", "", "") and self.allowNone:
            return None
        
        try:
            year, month, day = map(positiveInt, args)
        except ValueError:
            raise InputError, "Invalid date"
        if (month, day) == (2, 29):
            if not calendar.isleap(year):
                raise InputError, "%d was not a leap year" % year
            else:
                return year, month, day
        try:
            mdays = calendar.mdays[month]
        except IndexError:
            raise InputError, "Invalid date"
        if day > mdays:
            raise InputError, "Invalid date"
        return year, month, day 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:formmethod.py

示例5: _parse_text_representation

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import mdays [as 别名]
def _parse_text_representation(cls, string):
        """ Match common text representation for date """
        today = datetime.date.today()

        # accepted date formats
        formats = {
            'today': 0,
            _('today').lower(): 0,
            'tomorrow': 1,
            _('tomorrow').lower(): 1,
            'next week': 7,
            _('next week').lower(): 7,
            'next month': calendar.mdays[today.month],
            _('next month').lower(): calendar.mdays[today.month],
            'next year': 365 + int(calendar.isleap(today.year)),
            _('next year').lower(): 365 + int(calendar.isleap(today.year)),
        }

        # add week day names in the current locale
        for i, (english, local) in enumerate([
            ("Monday", _("Monday")),
            ("Tuesday", _("Tuesday")),
            ("Wednesday", _("Wednesday")),
            ("Thursday", _("Thursday")),
            ("Friday", _("Friday")),
            ("Saturday", _("Saturday")),
            ("Sunday", _("Sunday")),
        ]):
            offset = i - today.weekday() + 7 * int(i <= today.weekday())
            formats[english.lower()] = offset
            formats[local.lower()] = offset

        offset = formats.get(string, None)
        if offset is None:
            return None
        else:
            return today + datetime.timedelta(offset) 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:39,代码来源:dates.py

示例6: timegm

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import mdays [as 别名]
def timegm(year, month, day, hour, minute, second):
    """Convert time tuple in GMT to seconds since epoch, GMT"""
    EPOCH = 1970
    assert year >= EPOCH
    assert 1 <= month <= 12
    days = 365*(year-EPOCH) + calendar.leapdays(EPOCH, year)
    for i in range(1, month):
        days = days + calendar.mdays[i]
    if month > 2 and calendar.isleap(year):
        days = days + 1
    days = days + day - 1
    hours = days*24 + hour
    minutes = hours*60 + minute
    seconds = minutes*60 + second
    return seconds 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:17,代码来源:http.py

示例7: main

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import mdays [as 别名]
def main():
    months_out = 4
    now = datetime.now()
    dates = [now]

    for i in range(months_out):
        previous = dates[i]
        next_date = previous + timedelta(calendar.mdays[(previous.month % 12) + 1])
        dates.append(next_date)

    if not os.path.exists(conf["visual_web_dir"]):
        os.makedirs(conf["visual_web_dir"])

    _static_web = os.path.join(conf["visual_web_dir"], "static")
    if not os.path.exists(_static_web):
        _static = os.path.join(TEMPLATES_PATH, "static")
        os.symlink(_static, _static_web)

    for _date in dates:
        gen_time = "Allocation Map for %s-%.2d" % (_date.year, _date.month)
        content = generator(
            None, calendar.mdays[_date.month], _date.month, _date.year, gen_time
        )
        file_path = os.path.join(
            conf["visual_web_dir"], "%s-%.2d.html" % (_date.year, _date.month)
        )
        with open(file_path, "w+") as _file:
            _file.write(content)
        os.chmod(file_path, 0o644)

    _current = os.path.join(conf["visual_web_dir"], "current.html")
    _next = os.path.join(conf["visual_web_dir"], "next.html")
    if os.path.exists(_current):
        os.remove(_current)
    if os.path.exists(_next):
        os.remove(_next)

    current_path = os.path.join(
        conf["visual_web_dir"], "%s-%.2d.html" % (dates[0].year, dates[0].month)
    )
    os.symlink(current_path, _current)

    next_path = os.path.join(
        conf["visual_web_dir"], "%s-%.2d.html" % (dates[1].year, dates[1].month)
    )
    os.symlink(next_path, _next)

    files = [html for html in os.listdir(conf["visual_web_dir"]) if ".html" in html]
    lines = []
    for file in files:
        if file != "current.html" and file != "next.html" and file != "index.html":
            line = "<a href=%s>%s</a>\n<br>\n" % (file, file.split(".")[0])
            lines.append(line)

    index_path = os.path.join(conf["visual_web_dir"], "index.html")
    with open(index_path, "w+") as index:
        for line in lines:
            index.write(line) 
开发者ID:redhat-performance,项目名称:quads,代码行数:60,代码来源:simple_table_web.py


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