Back to index

plone3  3.1.7
dateIndexPatch.py
Go to the documentation of this file.
00001 # Avoid OverflowErrors in Date*Indexes
00002 
00003 from Products.PluginIndexes.DateIndex.DateIndex import DateIndex
00004 from Products.PluginIndexes.DateRangeIndex.DateRangeIndex import DateRangeIndex
00005 from DateTime import DateTime
00006 
00007 minDate = DateTime(-2113, 0)
00008 maxDate = DateTime(4008, 0)
00009 
00010 def _convert(self, value, default=None):
00011     try:
00012         return self.__old_convert(value, default)
00013     except OverflowError:
00014         return self.__old_convert(maxDate, default)
00015 
00016 DateIndex.__old_convert = DateIndex._convert
00017 DateIndex._convert = _convert
00018 
00019 def _convertDateTime(self, value):
00020     try:
00021         return self.__old_convertDateTime(value)
00022     except OverflowError:
00023         return self.__old_convertDateTime(maxDate)
00024 
00025 DateRangeIndex.__old_convertDateTime = DateRangeIndex._convertDateTime
00026 DateRangeIndex._convertDateTime = _convertDateTime
00027