Merge "normalise timestamp in query"
This commit is contained in:
commit
287377a41d
@ -19,6 +19,7 @@
|
||||
# under the License.
|
||||
|
||||
import ast
|
||||
import datetime
|
||||
import functools
|
||||
import inspect
|
||||
import json
|
||||
@ -129,7 +130,7 @@ class Query(Base):
|
||||
"""Query filter."""
|
||||
|
||||
# The data types supported by the query.
|
||||
_supported_types = ['integer', 'float', 'string', 'boolean']
|
||||
_supported_types = ['integer', 'float', 'string', 'boolean', 'datetime']
|
||||
|
||||
# Functions to convert the data field to the correct type.
|
||||
_type_converters = {'integer': int,
|
||||
@ -213,6 +214,8 @@ class Query(Base):
|
||||
# _type_converters to define their own types.
|
||||
raise TypeError()
|
||||
converted_value = self._type_converters[type](self.value)
|
||||
if isinstance(converted_value, datetime.datetime):
|
||||
converted_value = timeutils.normalize_time(converted_value)
|
||||
except ValueError:
|
||||
msg = (_('Unable to convert the value %(value)s'
|
||||
' to the expected data type %(type)s.') %
|
||||
|
@ -70,6 +70,14 @@ class TestQuery(base.BaseTestCase):
|
||||
expected = 'linux'
|
||||
self.assertEqual(expected, query._get_value_as_type())
|
||||
|
||||
def test_get_value_as_type_with_datetime(self):
|
||||
query = v2_base.Query(field='metadata.date',
|
||||
op='eq',
|
||||
value='2014-01-01T05:00:00',
|
||||
type='datetime')
|
||||
self.assertIsInstance(query._get_value_as_type(), datetime.datetime)
|
||||
self.assertIsNone(query._get_value_as_type().tzinfo)
|
||||
|
||||
def test_get_value_as_type_with_integer_without_type(self):
|
||||
query = v2_base.Query(field='metadata.size',
|
||||
op='eq',
|
||||
|
Loading…
Reference in New Issue
Block a user