Revision 1370
Added by Aaron Marcuse-Kubitza almost 13 years ago
dates.py | ||
---|---|---|
46 | 46 |
def could_be_day(str_): return str_.isdigit() and len(str_) <= 2 |
47 | 47 |
|
48 | 48 |
def parse_date_range(str_, range_sep='-', part_sep=' '): |
49 |
str_ = strings.single_space(str_)
|
|
49 |
default = (str_, None)
|
|
50 | 50 |
# range_sep might be used as date part separator instead |
51 |
if str_.find(part_sep) < 0: return (str_, None)
|
|
51 |
if str_.find(part_sep) < 0: return default
|
|
52 | 52 |
|
53 | 53 |
start, sep, end = str_.partition(range_sep) |
54 |
if sep == '': return (str_, None) # not a range |
|
55 |
start = start.split(part_sep) |
|
56 |
end = end.split(part_sep) |
|
54 |
if sep == '': return default # not a range |
|
55 |
start, end = (strings.single_space(d).split(part_sep) for d in (start, end)) |
|
57 | 56 |
|
58 | 57 |
# Has form M D1-D2 or M D1-D2 Y (not M1 Y1-M2 Y2 or M1 D1-M2 D2) |
59 | 58 |
if len(start) == 2 and (len(end) == 1 or ( |
... | ... | |
66 | 65 |
if ct_diff > 0: start += end[-ct_diff:] # make start fully specified |
67 | 66 |
# Other forms are invalid and will be left as-is |
68 | 67 |
|
69 |
return (start, end) |
|
68 |
return tuple(part_sep.join(d) for d in (start, end)) |
Also available in: Unified diff
dates.py: parse_date_range(): Fixed bug where the date parts were not joined back together into a string for each date range element. Use strings.single_space() after the date has been split into range parts so that whitespace around the range separator is removed instead of being replaced with a single space.