當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。