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


Python datetime.fromordinal方法代码示例

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


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

示例1: test_CCDCesque_changedates

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def test_CCDCesque_changedates(record):
    # Test start, end, and break dates of first two segments
    starts = [dt.strptime('1984-06-04', '%Y-%m-%d'),
              dt.strptime('1999-07-16', '%Y-%m-%d')]
    ends = [dt.strptime('1999-06-30', '%Y-%m-%d'),
            dt.strptime('2003-07-11', '%Y-%m-%d')]
    breaks = [dt.strptime('1999-07-16', '%Y-%m-%d'),
              dt.strptime('2003-07-27', '%Y-%m-%d')]

    for i in range(2):
        assert dt.fromordinal(record[i]['start']) == starts[i]
        assert dt.fromordinal(record[i]['end']) == ends[i]
        assert dt.fromordinal(record[i]['break']) == breaks[i]


# And now for the more hazardous tests on coefficents and RMSE 
开发者ID:ceholden,项目名称:yatsm,代码行数:18,代码来源:test_ccdcesque.py

示例2: ordinal2yeardoy

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def ordinal2yeardoy(ordinal):
    """ Convert ordinal dates to two arrays of year and doy

    Args:
        ordinal (np.ndarray): ordinal dates

    Returns:
        np.ndarray: nobs x 2 np.ndarray containing the year and DOY for each
            ordinal date

    """
    _date = [dt.fromordinal(_d) for _d in ordinal]
    yeardoy = np.empty((ordinal.size, 2), dtype=np.uint16)
    yeardoy[:, 0] = np.array([int(_d.strftime('%Y')) for _d in _date])
    yeardoy[:, 1] = np.array([int(_d.strftime('%j')) for _d in _date])

    return yeardoy 
开发者ID:ceholden,项目名称:yatsm,代码行数:19,代码来源:longtermmean.py

示例3: _from_ordinal

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def _from_ordinal(x, tz=None):
    ix = int(x)
    dt = datetime.fromordinal(ix)
    remainder = float(x) - ix
    hour, remainder = divmod(24 * remainder, 1)
    minute, remainder = divmod(60 * remainder, 1)
    second, remainder = divmod(60 * remainder, 1)
    microsecond = int(1e6 * remainder)
    if microsecond < 10:
        microsecond = 0  # compensate for rounding errors
    dt = datetime(dt.year, dt.month, dt.day, int(hour), int(minute),
                  int(second), microsecond)
    if tz is not None:
        dt = dt.astimezone(tz)

    if microsecond > 999990:  # compensate for rounding errors
        dt += timedelta(microseconds=1e6 - microsecond)

    return dt

# Fixed frequency dynamic tick locators and formatters

# -------------------------------------------------------------------------
# --- Locators ---
# ------------------------------------------------------------------------- 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:_converter.py

示例4: _from_ordinal

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def _from_ordinal(x, tz=None):
    ix = int(x)
    dt = datetime.fromordinal(ix)
    remainder = float(x) - ix
    hour, remainder = divmod(24 * remainder, 1)
    minute, remainder = divmod(60 * remainder, 1)
    second, remainder = divmod(60 * remainder, 1)
    microsecond = int(1e6 * remainder)
    if microsecond < 10:
        microsecond = 0  # compensate for rounding errors
    dt = datetime(dt.year, dt.month, dt.day, int(hour), int(minute),
                  int(second), microsecond)
    if tz is not None:
        dt = dt.astimezone(tz)

    if microsecond > 999990:  # compensate for rounding errors
        dt += timedelta(microseconds=1e6 - microsecond)

    return dt

### Fixed frequency dynamic tick locators and formatters

##### -------------------------------------------------------------------------
#---- --- Locators ---
##### ------------------------------------------------------------------------- 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:converter.py

示例5: datenum_to_datetime

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def datenum_to_datetime(datenum):
    """
    Convert Matlab datenum into Python datetime.
    Parameters
    ----------
    datenum: float
        date in datenum format

    Returns
    -------
    datetime :
        Datetime object corresponding to datenum.
    """
    days = datenum % 1.
    return datetime.fromordinal(int(datenum)) \
           + timedelta(days=days) - timedelta(days=366) 
开发者ID:pastas,项目名称:pastas,代码行数:18,代码来源:utils.py

示例6: datenum_to_datetime

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def datenum_to_datetime(datenum):
    """
    Convert Matlab datenum into Python datetime.
    """
    days = datenum % 1
    hours = days % 1 * 24
    minutes = hours % 1 * 60
    seconds = minutes % 1 * 60
    try:
        return (
            datetime.fromordinal(int(datenum))
            + timedelta(days=int(days))
            + timedelta(hours=int(hours))
            + timedelta(minutes=int(minutes))
            + timedelta(seconds=round(seconds))
            - timedelta(days=366)
        )
    except:
        return datenum_to_datetime(700000) 
开发者ID:keras-team,项目名称:autokeras,代码行数:21,代码来源:celeb_age.py

示例7: test_get_day_of_year_dt

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def test_get_day_of_year_dt():
    dt = datetime.fromordinal(1 + np.random.randint(365 * 4000))
    result = ccalendar.get_day_of_year(dt.year, dt.month, dt.day)

    expected = (dt - dt.replace(month=1, day=1)).days + 1
    assert result == expected 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_ccalendar.py

示例8: test_get_day_of_year

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def test_get_day_of_year():
    assert ccalendar.get_day_of_year(2001, 3, 1) == 60
    assert ccalendar.get_day_of_year(2004, 3, 1) == 61
    assert ccalendar.get_day_of_year(1907, 12, 31) == 365
    assert ccalendar.get_day_of_year(2004, 12, 31) == 366

    dt = datetime.fromordinal(1 + np.random.randint(365 * 4000))
    result = ccalendar.get_day_of_year(dt.year, dt.month, dt.day)
    expected = (dt - dt.replace(month=1, day=1)).days + 1
    assert result == expected 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,代码来源:test_ccalendar.py

示例9: test_days_ago

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def test_days_ago(self):
        today = pendulum.today()
        today_midnight = pendulum.instance(datetime.fromordinal(today.date().toordinal()))

        self.assertTrue(dates.days_ago(0) == today_midnight)

        self.assertTrue(dates.days_ago(100) == today_midnight + timedelta(days=-100))

        self.assertTrue(dates.days_ago(0, hour=3) == today_midnight + timedelta(hours=3))
        self.assertTrue(dates.days_ago(0, minute=3) == today_midnight + timedelta(minutes=3))
        self.assertTrue(dates.days_ago(0, second=3) == today_midnight + timedelta(seconds=3))
        self.assertTrue(dates.days_ago(0, microsecond=3) == today_midnight + timedelta(microseconds=3)) 
开发者ID:apache,项目名称:airflow,代码行数:14,代码来源:test_dates.py

示例10: _is_valid_episode

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def _is_valid_episode(episode_data, show_key):
    # Don't check old episodes (possible wrong season !)
    date_string = episode_data.find("meta", itemprop="dateCreated")["content"]
    date = datetime.fromordinal(dateutil.parser.parse(date_string).toordinal())

    if date > datetime.utcnow():
	    return False

    date_diff = datetime.utcnow() - date
    if date_diff >= timedelta(days=2):
	    debug("  Episode too old")
	    return False

    return True 
开发者ID:r-anime,项目名称:holo,代码行数:16,代码来源:adultswim.py

示例11: _digest_episode

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def _digest_episode(feed_episode):
    debug("Digesting episode")

    name = feed_episode.find("h4", itemprop="name", class_="episode__title").text
    link = feed_episode.find("a", itemprop="url", class_="episode__link").href
    num = int(feed_episode.find("meta", itemprop="episodeNumber")["content"])

    date_string = feed_episode.find("meta", itemprop="dateCreated")["content"]
    date = datetime.fromordinal(dateutil.parser.parse(date_string).toordinal())

    return Episode(num, name, link, date) 
开发者ID:r-anime,项目名称:holo,代码行数:13,代码来源:adultswim.py

示例12: test_fromordinal

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def test_fromordinal():
    assert datetime.fromordinal(730120) == pendulum.DateTime.fromordinal(730120) 
开发者ID:sdispater,项目名称:pendulum,代码行数:4,代码来源:test_behavior.py

示例13: calc_age

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def calc_age(taken, dob):
	birth = datetime.fromordinal(max(int(dob) - 366, 1))
	if birth.month < 7:
		return taken - birth.year
	else:
		return taken - birth.year - 1 
开发者ID:abars,项目名称:YoloKerasFaceDetection,代码行数:8,代码来源:annotation_imdb_keras.py

示例14: calc_age

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def calc_age(taken, dob):
    birth = datetime.fromordinal(max(int(dob) - 366, 1))
    if birth.month < 7:
        return taken - birth.year
    else:
        return taken - birth.year - 1 
开发者ID:KinarR,项目名称:age-gender-estimator-keras,代码行数:8,代码来源:utils.py

示例15: calculate_age

# 需要导入模块: from datetime import datetime [as 别名]
# 或者: from datetime.datetime import fromordinal [as 别名]
def calculate_age(taken, dob):
    birth = datetime.fromordinal(max(int(dob) - 366, 1))

    if birth.month < 7:
        return taken - birth.year
    else:
        return taken - birth.year - 1 
开发者ID:PacktPublishing,项目名称:Generative-Adversarial-Networks-Projects,代码行数:9,代码来源:run.py


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