3 def test_iso8601_regex():
4 assert iso8601.ISO8601_REGEX.match("2006-10-11T00:14:33Z")
6 def test_timezone_regex():
7 assert iso8601.TIMEZONE_REGEX.match("+01:00")
8 assert iso8601.TIMEZONE_REGEX.match("+00:00")
9 assert iso8601.TIMEZONE_REGEX.match("+01:20")
10 assert iso8601.TIMEZONE_REGEX.match("-01:00")
12 def test_parse_date():
13 d = iso8601.parse_date("2006-10-20T15:34:56Z")
20 assert d.tzinfo == iso8601.UTC
22 def test_parse_date_fraction():
23 d = iso8601.parse_date("2006-10-20T15:34:56.123Z")
30 assert d.microsecond == 123000
31 assert d.tzinfo == iso8601.UTC
33 def test_parse_date_fraction_2():
37 d = iso8601.parse_date("2007-5-7T11:43:55.328Z'")
44 assert d.microsecond == 328000
45 assert d.tzinfo == iso8601.UTC
47 def test_parse_date_tz():
48 d = iso8601.parse_date("2006-10-20T15:34:56.123+02:30")
55 assert d.microsecond == 123000
56 assert d.tzinfo.tzname(None) == "+02:30"
57 offset = d.tzinfo.utcoffset(None)
58 assert offset.days == 0
59 assert offset.seconds == 60 * 60 * 2.5
61 def test_parse_invalid_date():
63 iso8601.parse_date(None)
64 except iso8601.ParseError:
69 def test_parse_invalid_date2():
71 iso8601.parse_date("23")
72 except iso8601.ParseError:
77 def test_parse_no_timezone():
78 """issue 4 - Handle datetime string without timezone
80 This tests what happens when you parse a date with no timezone. While not
81 strictly correct this is quite common. I'll assume UTC for the time zone
84 d = iso8601.parse_date("2007-01-01T08:00:00")
91 assert d.microsecond == 0
92 assert d.tzinfo == iso8601.UTC
94 def test_parse_no_timezone_different_default():
95 tz = iso8601.FixedOffset(2, 0, "test offset")
96 d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)
99 def test_space_separator():
100 """Handle a separator other than T
103 d = iso8601.parse_date("2007-06-23 06:40:34.00Z")
104 assert d.year == 2007
108 assert d.minute == 40
109 assert d.second == 34
110 assert d.microsecond == 0
111 assert d.tzinfo == iso8601.UTC