def test02_str_to_datetime(self): """Reading.""" self.assertEqual(str_to_datetime("1970-01-01T00:00:00Z"), 0) self.assertEqual(str_to_datetime("1970-01-01T00:00:00.000Z"), 0) self.assertEqual(str_to_datetime("1970-01-01T00:00:00+00:00"), 0) self.assertEqual(str_to_datetime("1970-01-01T00:00:00-00:00"), 0) self.assertEqual(str_to_datetime("1970-01-01T00:00:00.000001Z"), 0.000001) self.assertEqual(str_to_datetime("1970-01-01T00:00:00.1Z"), 0.1) self.assertEqual(str_to_datetime("1970-01-01T00:00:00.100000Z"), 0.1) # Random other datetime self.assertEqual(str_to_datetime("2009-02-13T23:31:30Z"), 1234567890) # Special case self.assertEqual(str_to_datetime(None), None)
def test03_same(self): """Datetime values that are the same.""" astr = '2012-01-01T00:00:00Z' a = str_to_datetime(astr) for bstr in ( '2012', '2012-01', '2012-01-01', '2012-01-01T00:00Z', '2012-01-01T00:00:00Z', '2012-01-01T00:00:00.000000Z', '2012-01-01T00:00:00.000000000000Z', '2012-01-01T00:00:00.000000000001Z', # below resolution '2012-01-01T00:00:00.00+00:00', '2012-01-01T00:00:00.00-00:00', '2012-01-01T02:00:00.00-02:00', '2011-12-31T23:00:00.00+01:00'): b = str_to_datetime(bstr) self.assertEqual(a, b, ('%s (%f) == %s (%f)' % (astr, a, bstr, b)))
def rt(dts): """Do simple round-trip.""" return datetime_to_str(str_to_datetime(dts))