Log message for revision 101857:
  Added support to indexing datetime values to the PluginIndexes 
DateRangeIndex. The DateIndex already had this feature.
  

Changed:
  U   Zope/branches/2.12/doc/CHANGES.rst
  U   
Zope/branches/2.12/src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
  U   
Zope/branches/2.12/src/Products/PluginIndexes/DateRangeIndex/tests/test_DateRangeIndex.py

-=-
Modified: Zope/branches/2.12/doc/CHANGES.rst
===================================================================
--- Zope/branches/2.12/doc/CHANGES.rst  2009-07-13 15:45:41 UTC (rev 101856)
+++ Zope/branches/2.12/doc/CHANGES.rst  2009-07-13 16:25:34 UTC (rev 101857)
@@ -16,6 +16,9 @@
 
   * ZODB 3.9.0b2
 
+- Added support to indexing datetime values to the PluginIndexes
+  DateRangeIndex. The DateIndex already had this feature.
+
 Restructuring
 +++++++++++++
 

Modified: 
Zope/branches/2.12/src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
===================================================================
--- 
Zope/branches/2.12/src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py  
    2009-07-13 15:45:41 UTC (rev 101856)
+++ 
Zope/branches/2.12/src/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py  
    2009-07-13 16:25:34 UTC (rev 101857)
@@ -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/branches/2.12/src/Products/PluginIndexes/DateRangeIndex/tests/test_DateRangeIndex.py
===================================================================
--- 
Zope/branches/2.12/src/Products/PluginIndexes/DateRangeIndex/tests/test_DateRangeIndex.py
   2009-07-13 15:45:41 UTC (rev 101856)
+++ 
Zope/branches/2.12/src/Products/PluginIndexes/DateRangeIndex/tests/test_DateRangeIndex.py
   2009-07-13 16:25:34 UTC (rev 101857)
@@ -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 ) )

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to