[Zope-Checkins] SVN: Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/ Merged c101857 from 2.12 branch
Hanno Schlichting
hannosch at hannosch.eu
Mon Jul 13 12:26:41 EDT 2009
Log message for revision 101858:
Merged c101857 from 2.12 branch
Changed:
U Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
U Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/tests/test_DateRangeIndex.py
-=-
Modified: Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
===================================================================
--- Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py 2009-07-13 16:25:34 UTC (rev 101857)
+++ Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py 2009-07-13 16:26:41 UTC (rev 101858)
@@ -16,6 +16,7 @@
"""
import os
+from datetime import datetime
from AccessControl.Permissions import manage_zcatalog_indexes
from AccessControl.Permissions import view
@@ -385,10 +386,10 @@
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)
Modified: Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/tests/test_DateRangeIndex.py
===================================================================
--- Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/tests/test_DateRangeIndex.py 2009-07-13 16:25:34 UTC (rev 101857)
+++ Zope/trunk/src/Products/PluginIndexes/DateRangeIndex/tests/test_DateRangeIndex.py 2009-07-13 16:26:41 UTC (rev 101858)
@@ -141,7 +141,36 @@
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()
suite.addTest( unittest.makeSuite( DRI_Tests ) )
More information about the Zope-Checkins
mailing list