58
58
# offset of three minutes
59
59
self.assertEqual((1173193459, +3 * 60),
60
60
timestamp.parse_patch_date('2007-03-06 15:07:19 +0003'))
61
# No space between time and offset
62
self.assertEqual((1173193459, -5 * 3600),
63
timestamp.parse_patch_date('2007-03-06 10:04:19-0500'))
65
self.assertEqual((1173193459, -5 * 3600),
66
timestamp.parse_patch_date('2007-03-06 10:04:19 -0500'))
68
def test_parse_patch_date_bad(self):
69
self.assertRaises(ValueError, timestamp.parse_patch_date,
72
self.assertRaises(ValueError, timestamp.parse_patch_date,
73
'2007-03-06 10:04:19 -0500x')
75
self.assertRaises(ValueError, timestamp.parse_patch_date,
76
'2007-03 10:04:19 -0500')
78
self.assertRaises(ValueError, timestamp.parse_patch_date,
79
'2007-03-06 10:04 -0500')
81
self.assertRaises(ValueError, timestamp.parse_patch_date,
82
'2007-03-06 10:04:19')
83
# Missing plus or minus in offset
84
self.assertRaises(ValueError, timestamp.parse_patch_date,
85
'2007-03-06 10:04:19 0500')
86
# Invalid hour in offset
87
self.assertRaises(ValueError, timestamp.parse_patch_date,
88
'2007-03-06 10:04:19 +2400')
89
self.assertRaises(ValueError, timestamp.parse_patch_date,
90
'2007-03-06 10:04:19 -2400')
91
# Invalid minute in offset
92
self.assertRaises(ValueError, timestamp.parse_patch_date,
93
'2007-03-06 10:04:19 -0560')
94
# Too many digits in offset
95
self.assertRaises(ValueError, timestamp.parse_patch_date,
96
'2007-03-06 10:04:19 79500')
97
# Minus sign in middle of offset
98
self.assertRaises(ValueError, timestamp.parse_patch_date,
99
'2007-03-06 10:04:19 +05-5')
102
63
class UnpackHighresDateTests(tests.TestCase):
104
65
def test_unpack_highres_date(self):
106
67
(1120153132.3508501, -18000),
107
68
timestamp.unpack_highres_date('Thu 2005-06-30 12:38:52.350850105 -0500'))
109
70
(1120153132.3508501, 0),
110
71
timestamp.unpack_highres_date('Thu 2005-06-30 17:38:52.350850105 +0000'))
112
73
(1120153132.3508501, 7200),
113
74
timestamp.unpack_highres_date('Thu 2005-06-30 19:38:52.350850105 +0200'))
115
76
(1152428738.867522, 19800),
116
77
timestamp.unpack_highres_date('Sun 2006-07-09 12:35:38.867522001 +0530'))
128
89
o = ((o/3600 + 13) % 25 - 12)*3600 # Add 1 wrap around from [-12, 12]
129
90
date = timestamp.format_highres_date(t, o)
130
91
t2, o2 = timestamp.unpack_highres_date(date)
131
self.assertEqual(t, t2,
92
self.assertEquals(t, t2,
132
93
'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t))
133
self.assertEqual(o, o2,
94
self.assertEquals(o, o2,
134
95
'Failed on date %r, %s,%s diff:%s' % (date, t, o, t2-t))