summaryrefslogtreecommitdiff
path: root/src/isodate/isodatetime.py
diff options
context:
space:
mode:
authorAdrian Coveney <adrian.coveney@stfc.ac.uk>2014-08-19 14:33:21 +0100
committerAdrian Coveney <adrian.coveney@stfc.ac.uk>2014-08-19 15:02:34 +0100
commit343fcaee01b3908ded45f2c28e8e1a00d839ad5f (patch)
treeec23b856017f155e890dddd8894f1f0f55c01c1d /src/isodate/isodatetime.py
parent0f2e76b427d039bbc82f18b545f74db66d1c35c0 (diff)
downloadisodate-343fcaee01b3908ded45f2c28e8e1a00d839ad5f.tar.gz
Make parse_datetime raise ISO8601Error if no 'T'
- Make parse_datetime raise ISO8601Error if time designator 'T' is missing as before it would raise a ValueError that was hard to interpret. - Alter test_parse for test_datetime to check that bad inputs raise an ISO8601 error. The other tests did this, but test_datetime didn't. - Add test case where the 'T' time designator is missing from input datetime strings.
Diffstat (limited to 'src/isodate/isodatetime.py')
-rw-r--r--src/isodate/isodatetime.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/isodate/isodatetime.py b/src/isodate/isodatetime.py
index 147474b..9a5fce0 100644
--- a/src/isodate/isodatetime.py
+++ b/src/isodate/isodatetime.py
@@ -35,6 +35,7 @@ from datetime import datetime
from isodate.isostrf import strftime
from isodate.isostrf import DATE_EXT_COMPLETE, TIME_EXT_COMPLETE, TZ_EXT
from isodate.isodates import parse_date
+from isodate.isoerror import ISO8601Error
from isodate.isotime import parse_time
@@ -46,7 +47,11 @@ def parse_datetime(datetimestring):
more combinations of date and time representations, than the actual
ISO 8601:2004 standard allows.
'''
- datestring, timestring = datetimestring.split('T')
+ try:
+ datestring, timestring = datetimestring.split('T')
+ except ValueError:
+ raise ISO8601Error("ISO 8601 time designator 'T' missing. Unable to"
+ " parse datetime string %r" % datetimestring)
tmpdate = parse_date(datestring)
tmptime = parse_time(timestring)
return datetime.combine(tmpdate, tmptime)