3 from nose.tools import eq_
5 from ..timestamp import LONG_MW_TIME_STRING, Timestamp
9 t1 = Timestamp(1234567890)
12 eq_(t1, Timestamp(int(t1)))
15 eq_(t1, Timestamp(t1.short_format()))
18 eq_(t1, Timestamp(t1.long_format()))
21 def test_comparison():
22 t1 = Timestamp(1234567890)
23 t2 = Timestamp(1234567891)
25 assert t1 < t2, "Less than comparison failed"
26 assert t2 > t1, "Greater than comparison failed"
27 assert not t2 < t1, "Not less than comparison failed"
28 assert not t1 > t2, "Not greater than comparison failed"
30 assert t1 <= t2, "Less than or equal to comparison failed"
31 assert t1 <= t1, "Less than or equal to comparison failed"
32 assert t2 >= t1, "Greater than or equal to comparison failed"
33 assert t2 >= t2, "Greater than or equal to comparison failed"
34 assert not t2 <= t1, "Not less than or equal to comparison failed"
35 assert not t1 >= t2, "Not greater than or equal to comparison failed"
39 def test_subtraction():
40 t1 = Timestamp(1234567890)
41 t2 = Timestamp(1234567891)
50 Timestamp("2009-02-13T23:31:30Z"),
51 Timestamp.strptime("2009-02-13T23:31:30Z", LONG_MW_TIME_STRING)
56 "expires 03:20, 21 November 2013 (UTC)",
57 "expires %H:%M, %d %B %Y (UTC)"
59 Timestamp("2013-11-21T03:20:00Z")
65 Timestamp("2009-02-13T23:31:30Z").strftime(LONG_MW_TIME_STRING),
66 "2009-02-13T23:31:30Z"
70 Timestamp("2009-02-13T23:31:30Z").strftime("expires %H:%M, %d %B %Y (UTC)"),
71 "expires 23:31, 13 February 2009 (UTC)"
75 def test_serialization():
76 timestamp = Timestamp(1234567890)
79 Timestamp.deserialize(timestamp.serialize())
83 timestamp = Timestamp(1234567890)
86 pickle.loads(pickle.dumps(timestamp))