From 435aad50e45c59405e68a9759d483f09f03d4bf1 Mon Sep 17 00:00:00 2001 From: "laetitia.gangloff@acsone.eu" Date: Thu, 31 Jul 2014 16:51:38 +0200 Subject: [PATCH] in utc_midnight use timezone to compute it --- mis_builder/models/mis_builder.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index fa969e53..35e3ac9f 100644 --- a/mis_builder/models/mis_builder.py +++ b/mis_builder/models/mis_builder.py @@ -26,7 +26,7 @@ from datetime import datetime, timedelta from dateutil import parser import traceback import re -import calendar +import pytz from openerp.osv import orm, fields from openerp.tools.safe_eval import safe_eval @@ -49,13 +49,14 @@ def _get_selection_label(selection, value): return '' -def _utc_midnight(d, add_day=0): +def _utc_midnight(d, tz_name, add_day=0): d = datetime.strptime(d, tools.DEFAULT_SERVER_DATE_FORMAT) if add_day: d = d + timedelta(days=add_day) - timestamp = calendar.timegm(d.timetuple()) - d_utc_midnight = datetime.utcfromtimestamp(timestamp) - return datetime.strftime(d_utc_midnight, tools.DEFAULT_SERVER_DATETIME_FORMAT) + utc = pytz.timezone('UTC') + context_tz = pytz.timezone(tz_name) + utc_timestamp = utc.localize(d, is_dst=False) + return datetime.strftime(utc_timestamp.astimezone(context_tz), tools.DEFAULT_SERVER_DATETIME_FORMAT) def _clean(varStr): @@ -426,8 +427,8 @@ class mis_report_instance_period(orm.Model): domain.extend([(query.date_field.name, '>=', c.date_from), (query.date_field.name, '<=', c.date_to)]) else: - datetime_from = _utc_midnight(c.date_from) - datetime_to = _utc_midnight(c.date_to, add_day=1) + datetime_from = _utc_midnight(c.date_from, context.get('tz', 'UTC')) + datetime_to = _utc_midnight(c.date_to, context.get('tz', 'UTC'), add_day=1) domain.extend([(query.date_field.name, '>=', datetime_from), (query.date_field.name, '<', datetime_to)]) if obj._columns.get('company_id', False):