Commit d0893fea authored by Hanno Schlichting's avatar Hanno Schlichting

Added support to indexing datetime values to the PluginIndexes DateRangeIndex....

Added support to indexing datetime values to the PluginIndexes DateRangeIndex. The DateIndex already had this feature.
parent 5bde5c8f
......@@ -16,6 +16,9 @@ Features Added
* ZODB 3.9.0b2
- Added support to indexing datetime values to the PluginIndexes
DateRangeIndex. The DateIndex already had this feature.
Restructuring
+++++++++++++
......
......@@ -16,6 +16,7 @@ $Id$
"""
import os
from datetime import datetime
from AccessControl.Permissions import manage_zcatalog_indexes
from AccessControl.Permissions import view
......@@ -385,10 +386,10 @@ class DateRangeIndex(UnIndex):
def _convertDateTime( self, value ):
if value is None:
return value
if isinstance(value, str):
if isinstance(value, (str, datetime)):
dt_obj = DateTime( value )
value = dt_obj.millis() / 1000 / 60 # flatten to minutes
if isinstance(value, DateTime):
elif isinstance(value, DateTime):
value = value.millis() / 1000 / 60 # flatten to minutes
result = int( value )
if isinstance(result, long): # this won't work (Python 2.3)
......
......@@ -141,6 +141,35 @@ class DRI_Tests( unittest.TestCase ):
bad = Dummy( 'bad', long(sys.maxint) + 1, long(sys.maxint) + 1 )
work.index_object( 0, bad )
def test_datetime(self):
from datetime import datetime
before = datetime(2009, 7, 11, 0, 0)
start = datetime(2009, 7, 13, 5, 15)
between = datetime(2009, 7, 13, 5, 45)
stop = datetime(2009, 7, 13, 6, 30)
after = datetime(2009, 7, 14, 0, 0)
dummy = Dummy('test', start, stop)
work = DateRangeIndex( 'work', 'start', 'stop' )
work.index_object(0, dummy)
assert work.getEntryForObject(0) == (20790915, 20790990)
results, used = work._apply_index( { 'work' : before } )
assert len(results) == 0
results, used = work._apply_index( { 'work' : start } )
assert len(results) == 1
results, used = work._apply_index( { 'work' : between } )
assert len(results) == 1
results, used = work._apply_index( { 'work' : stop } )
assert len(results) == 1
results, used = work._apply_index( { 'work' : after } )
assert len(results) == 0
def test_suite():
suite = unittest.TestSuite()
......
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