From 6f488644e3069ca34d13ff5c4510cfe6f1faff94 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Thu, 22 Jan 2015 18:43:10 +0100 Subject: [PATCH] [gen] Table of indexes: indexed date values are now correctly displayed as DateTime instances. --- fields/date.py | 22 ++++++++++++++++++++++ gen/mixins/ToolMixin.py | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fields/date.py b/fields/date.py index eb6cf95..2ca9469 100644 --- a/fields/date.py +++ b/fields/date.py @@ -19,6 +19,28 @@ import time from appy.fields import Field 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): diff --git a/gen/mixins/ToolMixin.py b/gen/mixins/ToolMixin.py index f9475d4..e776a83 100644 --- a/gen/mixins/ToolMixin.py +++ b/gen/mixins/ToolMixin.py @@ -113,8 +113,8 @@ class ToolMixin(BaseMixin): res = index.getEntryForObject(catalogBrain.getRID()) if indexType == 'DateIndex': # The index value is a number. Add a DateTime representation too. - from DateTime import DateTime - res = '%d (%s)' % (res, DateTime(res)) + from appy.fields.date import getDateFromIndexValue + res = '%d (%s)' % (res, getDateFromIndexValue(res)) return res def getApp(self):