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


Python DateTime.rebuild方法代码示例

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


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

示例1: test_constructors

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import rebuild [as 别名]
def test_constructors():
    ## DateTime()
    d = DateTime(2008,1,2, 12,13,14)
    assert d.year == 2008
    assert d.month == 1
    assert d.day == 2
    assert d.hour == 12
    assert d.minute == 13
    assert d.second == 14
    assert d.absdate == 733043
    assert d.abstime == 43994.0
    assert long(d.absdays*1000) == 733042509L

    # Normalization
    assert DateTime(2008,1,-1).day == 31
    assert DateTime(2008,1,-31).day == 1
    assert DateTime(2008,-1,1).month == 12
    assert DateTime(2008,-12,1).month == 1
    assert DateTime(-1,1,1).year == -1

    # Range errors
    try:
        DateTime(2014, 9, 31)
    except RangeError:
        pass
    else:
        raise AssertionError('DateTime(2014, 9, 31) should raise a RangeError')
    try:
        MaxDateTime + 10
    except RangeError:
        pass
    else:
        raise AssertionError('MaxDateTime + 10 should raise a RangeError')
    try:
        MinDateTime - 10
    except RangeError:
        pass
    else:
        raise AssertionError('MinDateTime - 10 should raise a RangeError')

    # .rebuild()
    assert id(d) != id(d.rebuild())
    assert d.rebuild(year=2000) == DateTime(2000,1,2, 12,13,14)
    assert d.rebuild(month=11) == DateTime(2008,11,2, 12,13,14)
    assert d.rebuild(day=12) == DateTime(2008,1,12, 12,13,14)
    assert d.rebuild(hour=9) == DateTime(2008,1,2, 9,13,14)
    assert d.rebuild(minute=20) == DateTime(2008,1,2, 12,20,14)
    assert d.rebuild(second=33) == DateTime(2008,1,2, 12,13,33)
    assert d.rebuild(second=35.5) == DateTime(2008,1,2, 12,13,35.5)
    assert d.rebuild(year=2000, hour=10) == DateTime(2000,1,2, 10,13,14)

    ## Test DateTimeFromAbsDateTime()

    # wintertime
    t = DateTimeFromAbsDateTime(729368,55931.522913)
    print t
    print repr(t)
    assert str(t) == '1997-12-10 15:32:11.52'

    x = float(t)
    print 'as ticks:',x
    print 'time.gmtime:',time.gmtime(x),'(note the seconds)'
    print 'time.localtime:',time.localtime(x)
    print 'tuple:',t.tuple()

    print

    # summertime
    t = DateTimeFromAbsDateTime(729200,55931.522913)
    print t
    print repr(t)
    assert str(t) == '1997-06-25 15:32:11.52'

    x = float(t)
    print 'as ticks:',x
    print 'time.gmtime:',time.gmtime(x),'(note the seconds)'
    print 'time.localtime:',time.localtime(x)
    print 'tuple:',t.tuple()

    # Leap seconds
    try:
        leap_2008_0 = DateTimeFromAbsDateTime(733407, 86401.75)
    except RangeError:
        pass
    else:
        raise AssertionError('DateTimeFromAbsDateTime')
    leap_2008_1 = DateTimeFromAbsDateTime(733407, 86400.75)
    assert leap_2008_1.abstime == 86400.75
    assert str(leap_2008_1) == '2008-12-31 23:59:60.75'
    leap_2008_2 = DateTimeFromAbsDateTime(733407, 86400.99)
    assert leap_2008_2.abstime == 86400.99
    assert str(leap_2008_2) == '2008-12-31 23:59:60.99'
    leap_2008_2 = DateTimeFromAbsDateTime(733407, 86400.999)
    assert leap_2008_2.abstime == 86400.999
    assert str(leap_2008_2) == '2008-12-31 23:59:60.99'

    print

    ## Test Timestamp()
    t = Timestamp(1900,1,1,12,23,34.5)
#.........这里部分代码省略.........
开发者ID:rfleschenberg,项目名称:egenix-mx-base-python-2x3,代码行数:103,代码来源:test_test.py

示例2: long

# 需要导入模块: from mx import DateTime [as 别名]
# 或者: from mx.DateTime import rebuild [as 别名]
assert d.hour == 12
assert d.minute == 13
assert d.second == 14
assert d.absdate == 733043
assert d.abstime == 43994.0
assert long(d.absdays * 1000) == 733042509L

# Normalization
assert DateTime(2008, 1, -1).day == 31
assert DateTime(2008, 1, -31).day == 1
assert DateTime(2008, -1, 1).month == 12
assert DateTime(2008, -12, 1).month == 1
assert DateTime(-1, 1, 1).year == -1

# .rebuild()
assert id(d) != id(d.rebuild())
assert d.rebuild(year=2000) == DateTime(2000, 1, 2, 12, 13, 14)
assert d.rebuild(month=11) == DateTime(2008, 11, 2, 12, 13, 14)
assert d.rebuild(day=12) == DateTime(2008, 1, 12, 12, 13, 14)
assert d.rebuild(hour=9) == DateTime(2008, 1, 2, 9, 13, 14)
assert d.rebuild(minute=20) == DateTime(2008, 1, 2, 12, 20, 14)
assert d.rebuild(second=33) == DateTime(2008, 1, 2, 12, 13, 33)
assert d.rebuild(second=35.5) == DateTime(2008, 1, 2, 12, 13, 35.5)
assert d.rebuild(year=2000, hour=10) == DateTime(2000, 1, 2, 10, 13, 14)

## Test DateTimeFromAbsDateTime()

# wintertime
t = winter = DateTimeFromAbsDateTime(729368, 55931.522913)
print t
print repr(t)
开发者ID:GymWenFLL,项目名称:tpp_libs,代码行数:33,代码来源:test.py


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