本文整理汇总了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)
#.........这里部分代码省略.........
示例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)