Commit a4e1e8a3 authored by Chris McDonough's avatar Chris McDonough

Remove magical cast to int. Raise a ValueError explicitly when we

notice that the date is a long.
parent 60d04a03
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
############################################################################## ##############################################################################
"""$Id: DateRangeIndex.py,v 1.8 2003/11/02 11:57:58 chrism Exp $ """$Id: DateRangeIndex.py,v 1.9 2003/11/04 14:53:28 chrism Exp $
""" """
import os import os
...@@ -405,16 +405,11 @@ class DateRangeIndex(UnIndex): ...@@ -405,16 +405,11 @@ class DateRangeIndex(UnIndex):
value = dt_obj.millis() / 1000 / 60 # flatten to minutes value = dt_obj.millis() / 1000 / 60 # flatten to minutes
if isinstance( value, DateTime ): if isinstance( value, DateTime ):
value = value.millis() / 1000 / 60 # flatten to minutes value = value.millis() / 1000 / 60 # flatten to minutes
# XXX 2038K bug: result = int( value )
# we might still be dealing with a long. if isinstance(result, long): # this won't work
# we're using IOBTrees with dates as keys and we raise ValueError( '%s is not within the range of dates allowed'
# cant convert long to int if its > sys.maxint. 'by a DateRangeIndex' % value)
# BTrees code blows up if we try to ask it for a long key, return result
# so we punt here. In a future version, we should either
# come up with a LOBTree or use OOBTrees to store datum.
if value > sys.maxint:
value = sys.maxint
return int( value )
InitializeClass( DateRangeIndex ) InitializeClass( DateRangeIndex )
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
import Zope import Zope
import unittest import unittest
import sys
from Products.PluginIndexes.DateRangeIndex.DateRangeIndex import DateRangeIndex from Products.PluginIndexes.DateRangeIndex.DateRangeIndex import DateRangeIndex
...@@ -111,6 +112,13 @@ class DRI_Tests( unittest.TestCase ): ...@@ -111,6 +112,13 @@ class DRI_Tests( unittest.TestCase ):
for result, match in map( None, results, matches ): for result, match in map( None, results, matches ):
assert work.getEntryForObject( result ) == match.datum() assert work.getEntryForObject( result ) == match.datum()
def test_longdates( self ):
self.assertRaises(ValueError, self._badlong )
def _badlong(self):
work = DateRangeIndex ('work', 'start', 'stop' )
bad = Dummy( 'bad', sys.maxint + 1, sys.maxint + 1 )
work.index_object( 0, bad )
def test_suite(): def test_suite():
suite = unittest.TestSuite() 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