Skip to content

Commit 44f0e4b

Browse files
committed
Fix bug in (Date- or Interval-) Range parsing
Obscure case with only a "from" is now parsed correctly. Obviously it isn't possible to get the three cases with a missing "from" *or* a missing "to" or *both* (in which case the interval has zero length) right in a single regex. This also fixes broken unittests testFilteringRangeInterval and testFilteringRangeTwoSyntaxes (which used that syntax). This was introduced in 07c59221f363 but before that ranges with only a "to" didn't work.
1 parent 73c00b2 commit 44f0e4b

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

roundup/date.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,9 @@ def set(self, spec, allowdate=1, interval_re=re.compile('''
783783
if not m:
784784
m = interval_re.match(spec)
785785
if not m:
786-
raise ValueError, self._('Not an interval spec:'
787-
' [+-] [#y] [#m] [#w] [#d] [[[H]H:MM]:SS] [date spec]')
786+
raise ValueError, self._('Not an interval spec: "%s"'
787+
' ([+-] [#y] [#m] [#w] [#d] [[[H]H:MM]:SS] [date spec])'
788+
% spec)
788789
else:
789790
allowdate = 0
790791

@@ -805,8 +806,9 @@ def set(self, spec, allowdate=1, interval_re=re.compile('''
805806

806807
# make sure it's valid
807808
if not valid and not info['D']:
808-
raise ValueError, self._('Not an interval spec:'
809-
' [+-] [#y] [#m] [#w] [#d] [[[H]H:MM]:SS]')
809+
raise ValueError, self._('Not an interval spec: "%s"'
810+
' ([+-] [#y] [#m] [#w] [#d] [[[H]H:MM]:SS])'
811+
% spec)
810812

811813
if self.week:
812814
self.day = self.day + self.week*7
@@ -1127,6 +1129,12 @@ class Range:
11271129
>>> Range("; 20:00 +1d", Date)
11281130
<Range from None to 2003-03-09.20:00:00>
11291131
1132+
>>> Range("from 2003-02-16", Date)
1133+
<Range from 2003-02-16.00:00:00 to None>
1134+
1135+
>>> Range("2003-02-16;", Date)
1136+
<Range from 2003-02-16.00:00:00 to None>
1137+
11301138
Granularity tests:
11311139
11321140
>>> Range("12:00", Date)
@@ -1137,6 +1145,17 @@ class Range:
11371145
11381146
>>> test_fin(u)
11391147
1148+
Range of Interval tests
1149+
1150+
>>> Range ("from 0:50 to 2:00", Interval)
1151+
<Range from + 0:50 to + 2:00>
1152+
>>> Range ("from 0:50 to 1d 2:00", Interval)
1153+
<Range from + 0:50 to + 1d 2:00>
1154+
>>> Range ("from 5:50", Interval)
1155+
<Range from + 5:50 to None>
1156+
>>> Range ("to 0:05", Interval)
1157+
<Range from None to + 0:05>
1158+
11401159
"""
11411160
def __init__(self, spec, Type, allow_granularity=True, **params):
11421161
"""Initializes Range of type <Type> from given <spec> string.
@@ -1150,6 +1169,7 @@ class instance.
11501169
"""
11511170
self.range_type = Type
11521171
re_range = r'^(?:from)?(.+?)?to(.+?)?$'
1172+
re_range_no_to = r'^from(.+)(.)?$'
11531173
re_geek_range = r'^(.+?)?;(.+?)?$'
11541174
# Check which syntax to use
11551175
if ';' in spec:
@@ -1158,6 +1178,8 @@ class instance.
11581178
else:
11591179
# Native english
11601180
m = re.search(re_range, spec.strip(), re.IGNORECASE)
1181+
if not m :
1182+
m = re.search(re_range_no_to, spec.strip(), re.IGNORECASE)
11611183
if m:
11621184
self.from_value, self.to_value = m.groups()
11631185
if self.from_value:

0 commit comments

Comments
 (0)