Skip to content

Commit 5fa6571

Browse files
authored
Ensure that malformed datetime points with > 1 "T" raise the correct error (#266)
1 parent 5c879b9 commit 5fa6571

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Requires Python 3.9+
2020

2121
### Fixes
2222

23+
[#266](https://github.com/metomi/isodatetime/pull/234):
24+
Fixed a bug causing unhelpful error messages when parsing a
25+
malformed time-point containing >1 letter "T".
26+
2327
[#234](https://github.com/metomi/isodatetime/pull/234):
2428
Fixed behaviour of adding a truncated TimePoint to a normal TimePoint.
2529

metomi/isodatetime/parsers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def get_info(self, timepoint_string):
439439
time_zone_info = (
440440
self.process_time_zone_info({}))
441441
time_info.update(time_zone_info)
442-
else:
442+
elif len(date_time_time_zone) == 2:
443443
date, time_time_zone = date_time_time_zone
444444
if not date and self.allow_truncated:
445445
keys = (None, "truncated", "")
@@ -501,6 +501,8 @@ def get_info(self, timepoint_string):
501501
parsed_expr += parser_spec.TIME_DESIGNATOR + (
502502
time_expr + time_zone_expr)
503503
time_info.update(time_zone_info)
504+
else:
505+
raise ISO8601SyntaxError('time', timepoint_string)
504506
return date_info, time_info, parsed_expr
505507

506508
def process_time_zone_info(self, time_zone_info=None):

metomi/isodatetime/tests/test_time_point.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import random
2424

2525
from metomi.isodatetime.data import TimePoint, Duration, get_days_since_1_ad
26+
from metomi.isodatetime.parsers import TimePointParser
27+
from metomi.isodatetime.exceptions import ISO8601SyntaxError
2628

2729

2830
def daterange(start_date, end_date):
@@ -123,3 +125,12 @@ def _test_timepoint(test_year):
123125
test_data.get_calendar_date(),
124126
test_data.get_hour_minute_second()]
125127
assert test_data == ctrl_data
128+
129+
130+
def test_invalid_point():
131+
"""Check that invalid points return a sensible failure.
132+
"""
133+
bad = 'STARTTIMET0000Z'
134+
tpp = TimePointParser()
135+
with pytest.raises(ISO8601SyntaxError, match=bad):
136+
tpp.parse(bad)

0 commit comments

Comments
 (0)