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


Python calendar.isleap方法代码示例

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


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

示例1: test_simple_model_with_annual_licence_multi_year

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def test_simple_model_with_annual_licence_multi_year(simple_linear_model):
    """ Test the AnnualLicense over multiple years
    """
    import pandas as pd
    import datetime, calendar
    m = simple_linear_model
    # Modify model to run for 3 years of non-leap years at 30 day time-step.
    m.timestepper.start = pd.to_datetime('2017-1-1')
    m.timestepper.end = pd.to_datetime('2020-1-1')
    m.timestepper.delta = datetime.timedelta(30)

    annual_total = 365.0
    lic = AnnualLicense(m, m.nodes["Input"], annual_total)
    # Apply licence to the model
    m.nodes["Input"].max_flow = lic
    m.nodes["Output"].max_flow = 10.0
    m.nodes["Output"].cost = -10.0
    m.setup()

    for i in range(len(m.timestepper)):
        m.step()
        days_in_year = 365 + int(calendar.isleap(m.timestepper.current.datetime.year))
        assert_allclose(m.nodes["Output"].flow, annual_total/days_in_year) 
开发者ID:pywr,项目名称:pywr,代码行数:25,代码来源:test_license.py

示例2: getDOB

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def getDOB(self):
        year = self.getyear()
        month = self.getmonth()
        
        if calendar.isleap(year) and month=='February':
            self.lastday =  29
        elif not calendar.isleap(year) and month=='February':
            self.lastday = 28
        elif month in ('January', 'March', 'May', 'July', 'August', 'October', 'December'):
            self.lastday = 31
        elif month in ('April', 'June', 'September', 'November'):
            self.lastday = 30
        else:
            self.lastday = -1
        
        if self.getdate() > self.lastday or self.getdate()<1 or self.lastday == -1:
            date = -1
        else:
            date = self.getdate()
        
        if year != -1 and month != -1 and date != -1:
            self.displaydob.config(text = '{0} {1}, {2}'.format(month, date, year))
        else:
            self.displaydob.config(text = "Invalid Date") 
开发者ID:adipandas,项目名称:python-gui-demos,代码行数:26,代码来源:program7.py

示例3: W

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def W(self):
        "ISO-8601 week number of year, weeks starting on Monday"
        # Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt
        week_number = None
        jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1
        weekday = self.data.weekday() + 1
        day_of_year = self.z()
        if day_of_year <= (8 - jan1_weekday) and jan1_weekday > 4:
            if jan1_weekday == 5 or (jan1_weekday == 6 and calendar.isleap(self.data.year - 1)):
                week_number = 53
            else:
                week_number = 52
        else:
            if calendar.isleap(self.data.year):
                i = 366
            else:
                i = 365
            if (i - day_of_year) < (4 - weekday):
                week_number = 1
            else:
                j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
                week_number = j // 7
                if jan1_weekday > 4:
                    week_number -= 1
        return week_number 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:dateformat.py

示例4: W

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def W(self):
        "ISO-8601 week number of year, weeks starting on Monday"
        # Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt
        jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1
        weekday = self.data.weekday() + 1
        day_of_year = self.z()
        if day_of_year <= (8 - jan1_weekday) and jan1_weekday > 4:
            if jan1_weekday == 5 or (jan1_weekday == 6 and calendar.isleap(self.data.year - 1)):
                week_number = 53
            else:
                week_number = 52
        else:
            if calendar.isleap(self.data.year):
                i = 366
            else:
                i = 365
            if (i - day_of_year) < (4 - weekday):
                week_number = 1
            else:
                j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
                week_number = j // 7
                if jan1_weekday > 4:
                    week_number -= 1
        return week_number 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:26,代码来源:dateformat.py

示例5: gregorian_valid

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def gregorian_valid(date_tuple):
    """ Checks if date_tuple is a valid date in Gregorian Calendar  """
    day = date_tuple[0]
    month = date_tuple[1]
    valid = True
    try:
        if month > 12:
            valid = False
        elif calendar.isleap(date_tuple[2]):
            if day > _leap_days[month-1]:
                valid = False
        elif day > _max_days[month-1]:
            valid = False
    except:
        valid = False
    return valid 
开发者ID:GenealogyCollective,项目名称:gprime,代码行数:18,代码来源:_dateparser.py

示例6: timegm

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [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

示例7: coerce

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [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

示例8: _calendar_month_middles

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [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

示例9: _make_date_from_match

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def _make_date_from_match(match):
    g = match.groupdict()
    if g['month']:
        return datetime.date(int(g['year']),
                             int(g['month']),
                             int(g['day']))
    elif g['isoweek']:
        return date_by_isoweekday(int(g['year']),
                                  int(g['isoweek']),
                                  int(g['isoweekday']))
    else:
        year = int(g['year'])
        ordinalday = int(g['ordinalday'])
        if not 1 <= ordinalday <= 366:
            raise ValueError('ordinal day number {!r} is out of '
                             'range 001..366'.format(ordinalday))
        if ordinalday == 366 and not calendar.isleap(year):
            raise ValueError('ordinal day number {!r} is out of range '
                             'for year {!r} (which is not a leap year)'
                             .format(ordinalday, year))
        return date_by_ordinalday(year, ordinalday) 
开发者ID:CERT-Polska,项目名称:n6,代码行数:23,代码来源:datetime_helpers.py

示例10: _get_fy_duration_factor

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def _get_fy_duration_factor(self, cr, uid, entry, asset, firstyear, context=None):
        """ localization: override this method to change the logic used to calculate the impact of extended/shortened fiscal years """
        duration_factor = 1.0
        fy_id = entry['fy_id']
        if asset.prorata:
            if firstyear:
                depreciation_date_start = datetime.strptime(asset.date_start, '%Y-%m-%d')
                fy_date_stop = entry['date_stop']
                first_fy_asset_days = (fy_date_stop - depreciation_date_start).days + 1
                if fy_id:
                    first_fy_duration = self._get_fy_duration(cr, uid, fy_id, option='days')
                    first_fy_year_factor = self._get_fy_duration(cr, uid, fy_id, option='years')
                    duration_factor = float(first_fy_asset_days) / first_fy_duration * first_fy_year_factor
                else:
                    first_fy_duration = calendar.isleap(entry['date_start'].year) and 366 or 365
                    duration_factor = float(first_fy_asset_days) / first_fy_duration
            elif fy_id:
                duration_factor = self._get_fy_duration(cr, uid, fy_id, option='years')
        elif fy_id:
            fy_months = self._get_fy_duration(cr, uid, fy_id, option='months')
            duration_factor = float(fy_months) / 12
        return duration_factor 
开发者ID:iw3hxn,项目名称:LibrERP,代码行数:24,代码来源:account_asset.py

示例11: get_date_range_hours_from_year

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def get_date_range_hours_from_year(year):
    """
    creates date range in hours for the year excluding leap day
    :param year: year of date range
    :type year: int
    :return: pd.date_range with 8760 values
    :rtype: pandas.data_range
    """

    date_range = pd.date_range(start=str(year), end=str(year + 1), freq='H', closed='left')

    # Check if leap year and remove extra day
    if isleap(year):
        date_range = date_range[~((date_range.month == 2) & (date_range.day == 29))]

    return date_range 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:18,代码来源:date.py

示例12: to_jd

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def to_jd(year, month, day):
    legal_date(year, month, day)

    if month <= 2:
        leap_adj = 0
    elif isleap(year):
        leap_adj = -1
    else:
        leap_adj = -2

    return (
        EPOCH - 1 + (YEAR_DAYS * (year - 1)) +
        floor((year - 1) / LEAP_CYCLE_YEARS) +
        (-floor((year - 1) / LEAP_SUPPRESSION_YEARS)) +
        floor((year - 1) / INTERCALATION_CYCLE_YEARS) +
        floor((((367 * month) - 362) / 12) + leap_adj + day)
    ) 
开发者ID:fitnr,项目名称:convertdate,代码行数:19,代码来源:gregorian.py

示例13: legal_date

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def legal_date(year, month, day):
    '''Checks if a given date is a legal positivist date'''
    try:
        assert year >= 1
        assert 0 < month <= 14
        assert 0 < day <= 28
        if month == 14:
            if isleap(year + YEAR_EPOCH - 1):
                assert day <= 2
            else:
                assert day == 1

    except AssertionError:
        raise ValueError("Invalid Positivist date: ({}, {}, {})".format(year, month, day))

    return True 
开发者ID:fitnr,项目名称:convertdate,代码行数:18,代码来源:positivist.py

示例14: dayname

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def dayname(year, month, day):
    '''
    Give the name of the month and day for a given date.

    Returns:
        tuple month_name, day_name
    '''
    legal_date(year, month, day)

    yearday = (month - 1) * 28 + day

    if isleap(year + YEAR_EPOCH - 1):
        dname = data.day_names_leap[yearday - 1]
    else:
        dname = data.day_names[yearday - 1]

    return MONTHS[month - 1], dname 
开发者ID:fitnr,项目名称:convertdate,代码行数:19,代码来源:positivist.py

示例15: date_between

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import isleap [as 别名]
def date_between(s, e):
    y = randint(s.year, e.year)
    m = randint(1, 12)
    d = randint(1, 30)

    if calendar.isleap(y):
        if m == 2:
            d = randint(1, 29)

    if m == 2:
        d = randint(1, 28)

    h = randint(0, 12)
    i = randint(0, 59)
    s = randint(0, 59)

    return datetime(y, m, d, h, i, s) 
开发者ID:AvinashSingh786,项目名称:Fraud-Analysis,代码行数:19,代码来源:createDatabase.py


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