Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"2018-01-02", # Missing mandatory time
"2018-01-02T03", # Missing mandatory minute and second
"2018-01-02T03Z", # Missing mandatory minute and second
"2018-01-02T03:04", # Missing mandatory minute and second
"2018-01-02T03:04Z", # Missing mandatory minute and second
"2018-01-02T03:04:01+04", # Missing mandatory offset minute
"2018-01-02T03:04:05", # Missing mandatory offset
"2018-01-02T03:04:05.12345", # Missing mandatory offset
"2018-01-02T24:00:00Z", # 24:00:00 is not valid in RFC 3339
'20180102T03:04:05-12:34', # Missing mandatory date separators
'2018-01-02T030405-12:34', # Missing mandatory time separators
'2018-01-02T03:04:05-1234', # Missing mandatory offset separator
'2018-01-02T03:04:05,12345Z' # Invalid comma fractional second separator
]:
with self.assertRaisesRegex(ValueError, r"RFC 3339", msg="Timestamp '{0}' was supposed to be invalid, but parsing it didn't raise ValueError.".format(timestamp)):
ciso8601.parse_rfc3339(timestamp)
Validate that valid RFC 3339 datetimes are parseable by parse_rfc3339
and produce the same result as parse_datetime.
"""
for string in [
'2018-01-02T03:04:05Z',
'2018-01-02t03:04:05z',
'2018-01-02 03:04:05z',
'2018-01-02T03:04:05+00:00',
'2018-01-02T03:04:05-00:00',
'2018-01-02T03:04:05.12345Z',
'2018-01-02T03:04:05+01:23',
'2018-01-02T03:04:05-12:34',
'2018-01-02T03:04:05-12:34',
]:
self.assertEqual(ciso8601.parse_datetime(string),
ciso8601.parse_rfc3339(string))