MoinSupport

Annotated tests/test_dates.py

118:791ab8b6dd9d
2015-01-28 Paul Boddie Merged changes from the default branch. recurrences
paul@8 1
#!/usr/bin/env python
paul@8 2
paul@8 3
from DateSupport import *
paul@8 4
paul@8 5
d1 = DateTime((2012, 3, 25, 20, 45, 30, "Europe/Oslo"))
paul@8 6
d2 = DateTime((2012, 3, 25, 21, 05, 25, "Europe/Oslo"))
paul@8 7
ts1 = Timespan(d1, d1)
paul@8 8
ts2 = Timespan(d1, d2)
paul@8 9
paul@55 10
d1_roundtrip = getDateTimeFromISO8601(d1.as_ISO8601_datetime_string())
paul@55 11
d2_roundtrip = getDateTimeFromISO8601(d2.as_ISO8601_datetime_string())
paul@55 12
paul@55 13
#                              expected            result              operands
paul@55 14
print "%r : %r <- %r == %r" % (d1 == d1_roundtrip, d1 == d1_roundtrip, d1, d1_roundtrip)
paul@55 15
print "%r : %r <- %r == %r" % (d2 == d2_roundtrip, d2 == d2_roundtrip, d2, d2_roundtrip)
paul@53 16
paul@8 17
#                              expected         result        operands
paul@8 18
print "%r : %r <- %r < %r"  % (d1 < d2,         d1 < d2,      d1, d2)
paul@8 19
print "%r : %r <- %r == %r" % (not d1 == d2,    d1 == d2,     d1, d2)
paul@8 20
print "%r : %r <- %r < %r"  % (ts1 < ts2,       ts1 < ts2,    ts1, ts2)
paul@8 21
print "%r : %r <- %r == %r" % (not ts1 == ts2,  ts1 == ts2,   ts1, ts2)
paul@8 22
paul@8 23
d2_offset = d2.utc_offset()
paul@8 24
paul@8 25
#                                     expected             result       operands
paul@8 26
print "%r : %r <- %r.utc_offset()" % (d2_offset == (2, 0), d2_offset,   d2)
paul@8 27
paul@8 28
d3 = DateTime((2012, 3, 25, 21, 05, 25, "America/Montreal"))
paul@8 29
d4 = DateTime((2012, 3, 25, 21, 05, 25, "America/Anchorage"))
paul@8 30
d5 = DateTime((2012, 3, 25, 21, 05, 25, "America/St_Johns"))
paul@8 31
d6 = DateTime((2012, 3, 25, 21, 05, 25, "America/Vancouver"))
paul@8 32
d7 = DateTime((2012, 3, 25, 21, 05, 25, "-05:45"))
paul@8 33
d8 = DateTime((2012, 3, 25, 21, 05, 25, "05:45"))
paul@8 34
paul@8 35
#                              expected         result        operands
paul@8 36
print "%r : %r <- %r < %r"  % (d2 < d3,         d2 < d3,      d2, d3)
paul@8 37
print "%r : %r <- %r < %r"  % (d3 < d4,         d3 < d4,      d3, d4)
paul@8 38
print "%r : %r <- %r > %r"  % (d4 > d5,         d4 > d5,      d4, d5)
paul@8 39
print "%r : %r <- %r > %r"  % (not d5 > d6,     d5 > d6,      d5, d6)
paul@8 40
print "%r : %r <- %r > %r"  % (d6 > d7,         d6 > d7,      d6, d7)
paul@8 41
print "%r : %r <- %r > %r"  % (d7 > d8,         d7 > d8,      d7, d8)
paul@8 42
paul@8 43
d3_offset = d3.utc_offset()
paul@8 44
d4_offset = d4.utc_offset()
paul@8 45
d5_offset = d5.utc_offset()
paul@8 46
d6_offset = d6.utc_offset()
paul@8 47
d7_offset = d7.utc_offset()
paul@8 48
d8_offset = d8.utc_offset()
paul@8 49
paul@8 50
#                                     expected                  result       operands
paul@8 51
print "%r : %r <- %r.utc_offset()" % (d3_offset == (-4, 0),     d3_offset,   d3)
paul@8 52
print "%r : %r <- %r.utc_offset()" % (d4_offset == (-8, 0),     d4_offset,   d4)
paul@8 53
print "%r : %r <- %r.utc_offset()" % (d5_offset == (-2, -30),   d5_offset,   d5)
paul@8 54
print "%r : %r <- %r.utc_offset()" % (d6_offset == (-7, 0),     d6_offset,   d6)
paul@8 55
print "%r : %r <- %r.utc_offset()" % (d7_offset == (-5, -45),   d7_offset,   d7)
paul@8 56
print "%r : %r <- %r.utc_offset()" % (d8_offset == (5, 45),     d8_offset,   d8)
paul@8 57
paul@8 58
#                              expected                 result        operands
paul@8 59
print "%r : %r <- %r - %r"  % (d2 - d2 == 0,            d2 - d2,      d2, d2)
paul@8 60
print "%r : %r <- %r - %r"  % (d3 - d2 == 6 * 3600,     d3 - d2,      d3, d2)
paul@8 61
print "%r : %r <- %r - %r"  % (d4 - d2 == 10 * 3600,    d4 - d2,      d4, d2)
paul@8 62
print "%r : %r <- %r - %r"  % (d5 - d2 == 4.5 * 3600,   d5 - d2,      d5, d2)
paul@8 63
print "%r : %r <- %r - %r"  % (d6 - d2 == 9 * 3600,     d6 - d2,      d6, d2)
paul@8 64
print "%r : %r <- %r - %r"  % (d7 - d2 == 7.75 * 3600,  d7 - d2,      d7, d2)
paul@8 65
print "%r : %r <- %r - %r"  % (d8 - d2 == -3.75 * 3600, d8 - d2,      d8, d2)
paul@8 66
paul@8 67
# vim: tabstop=4 expandtab shiftwidth=4