[gen] Table of indexes: indexed date values are now correctly displayed as DateTime instances.
This commit is contained in:
parent
195adf8d11
commit
6f488644e3
|
@ -19,6 +19,28 @@ import time
|
||||||
from appy.fields import Field
|
from appy.fields import Field
|
||||||
from appy.px import Px
|
from appy.px import Px
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
def getDateFromIndexValue(indexValue):
|
||||||
|
'''p_indexValue is the internal representation of a date as stored in the
|
||||||
|
zope Date index (see "_convert" method in DateIndex.py in
|
||||||
|
Products.pluginIndexes/DateIndex). This function produces a DateTime
|
||||||
|
based on it.'''
|
||||||
|
# p_indexValue represents a number of minutes
|
||||||
|
minutes = indexValue % 60
|
||||||
|
indexValue = (indexValue-minutes) / 60 # The remaining part, in hours
|
||||||
|
# Get hours
|
||||||
|
hours = indexValue % 24
|
||||||
|
indexValue = (indexValue-hours) / 24 # The remaining part, in days
|
||||||
|
# Get days
|
||||||
|
day = indexValue % 31
|
||||||
|
indexValue = (indexValue-day) / 31 # The remaining part, in months
|
||||||
|
# Get months
|
||||||
|
month = indexValue % 12
|
||||||
|
year = (indexValue - month) / 12
|
||||||
|
from DateTime import DateTime
|
||||||
|
utcDate = DateTime('%d/%d/%d %d:%d UTC' % (year,month,day,hours,minutes))
|
||||||
|
return utcDate.toZone(utcDate.localZone())
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class Date(Field):
|
class Date(Field):
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,8 @@ class ToolMixin(BaseMixin):
|
||||||
res = index.getEntryForObject(catalogBrain.getRID())
|
res = index.getEntryForObject(catalogBrain.getRID())
|
||||||
if indexType == 'DateIndex':
|
if indexType == 'DateIndex':
|
||||||
# The index value is a number. Add a DateTime representation too.
|
# The index value is a number. Add a DateTime representation too.
|
||||||
from DateTime import DateTime
|
from appy.fields.date import getDateFromIndexValue
|
||||||
res = '%d (%s)' % (res, DateTime(res))
|
res = '%d (%s)' % (res, getDateFromIndexValue(res))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def getApp(self):
|
def getApp(self):
|
||||||
|
|
Loading…
Reference in a new issue