Commit 18304d29 authored by Vincent Pelletier's avatar Vincent Pelletier

Fix DateTimeKey behaviour toward bogus values.

DateTimeKey is capable of completing dates given with less than 3 parts (year,
month and day). This means less than 2 separators, not 3.
Also, be resilient to string which, when split by separators, generate an empty
list.
Add test cases.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44048 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ff80b5f6
......@@ -72,7 +72,7 @@ def castDate(value):
value = _DateTime(value, **date_kw)
except DateTimeError:
delimiter_count = countDelimiters(value)
if delimiter_count < 3:
if delimiter_count is not None and delimiter_count < 2:
split_value = value.split()
if split_value[-1].lower() in timezone_dict:
value = '%s %s' % (date_completion_format_dict[date_kw.get('datefmt')][delimiter_count] % (' '.join(split_value[:-1]), ), split_value[-1])
......@@ -101,6 +101,8 @@ def countDelimiters(value):
assert isinstance(value, basestring)
# Detect if timezone was provided, to avoid counting it as in precision computation.
split_value = value.split()
if not split_value:
return None
if split_value[-1].lower() in timezone_dict:
value = ' '.join(split_value[:-1])
# Count delimiters
......
......@@ -363,6 +363,20 @@ class TestSQLCatalog(unittest.TestCase):
def test_DateTimeKey(self):
self._testDateTimeKey('date')
# XXX: It is unknown what these tests should produce when used with a
# related key: should the join happen or not ?
self.catalog(
ReferenceQuery(ReferenceQuery([], operator='or'), operator='and'),
{'date': ' '})
self.catalog(
ReferenceQuery(ReferenceQuery([], operator='or'), operator='and'),
{'date': '<>2008/01/01'})
self.catalog(
ReferenceQuery(ReferenceQuery([], operator='or'), operator='and'),
{'date': '<'})
self.catalog(
ReferenceQuery(ReferenceQuery([], operator='or'), operator='and'),
{'date': '00:00:00'})
def test_relatedDateTimeKey(self):
self._testDateTimeKey('related_date')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment