Merge pull request #4571 from pbrunier/develop

Improvement for timerange parser
This commit is contained in:
Matthias 2021-03-19 06:36:22 +01:00 committed by GitHub
commit c304651249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -103,5 +103,7 @@ class TimeRange:
stop = int(stops) // 1000 stop = int(stops) // 1000
else: else:
stop = int(stops) stop = int(stops)
if start > stop > 0:
raise Exception('Start date is after stop date for timerange "%s"' % text)
return TimeRange(stype[0], stype[1], start, stop) return TimeRange(stype[0], stype[1], start, stop)
raise Exception('Incorrect syntax for timerange "%s"' % text) raise Exception('Incorrect syntax for timerange "%s"' % text)

View File

@ -30,6 +30,9 @@ def test_parse_timerange_incorrect():
with pytest.raises(Exception, match=r'Incorrect syntax.*'): with pytest.raises(Exception, match=r'Incorrect syntax.*'):
TimeRange.parse_timerange('-') TimeRange.parse_timerange('-')
with pytest.raises(Exception, match=r'Start date is after stop date for timerange.*'):
TimeRange.parse_timerange('20100523-20100522')
def test_subtract_start(): def test_subtract_start():
x = TimeRange('date', 'date', 1274486400, 1438214400) x = TimeRange('date', 'date', 1274486400, 1438214400)