From 3b6591bec34e7a4fc42ec7379401ca86a530694b Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Thu, 11 Jun 2009 10:45:27 +0000
Subject: [PATCH] keep the same timezone as input

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27520 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/DateUtils.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/product/ERP5Type/DateUtils.py b/product/ERP5Type/DateUtils.py
index c5c9e94a22..22f6d4ec29 100644
--- a/product/ERP5Type/DateUtils.py
+++ b/product/ERP5Type/DateUtils.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 #############################################################################
 #
 # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
@@ -31,6 +32,7 @@ import warnings
 from AccessControl import ModuleSecurityInfo
 from DateTime import DateTime
 from datetime import datetime
+from string import zfill
 from zLOG import LOG
 
 security = ModuleSecurityInfo('Products.ERP5Type.DateUtils')
@@ -501,16 +503,20 @@ def atTheEndOfPeriod(date, period):
   2000/01/15, month => 2000/02/01
   2000/01/18, week => 2000/01/24
   2000/01/20, day => 2000/01/21
+  If timezone is Universal, strftime('%Z') return empty string
+  and TimeZone is replaced by local zone, 
+  so date formating is manualy rendered.
+  XXXSunday is hardcoded
   """
   if period == 'year':
-    end = addToDate(DateTime(date.strftime('%Y/01/01 00:00:00')), **{period:1})
+    end = addToDate(DateTime('%s/01/01 00:00:00 %s' % (date.year(), date.timezone())), **{period:1})
   elif period == 'month':
-    end = addToDate(DateTime(date.strftime('%Y/%m/01 00:00:00')), **{period:1})
+    end = addToDate(DateTime('%s/%s/01 00:00:00 %s' % (date.year(), zfill(date.month(), 2), date.timezone())), **{period:1})
   elif period == 'day':
-    end = addToDate(DateTime(date.strftime('%Y/%m/%d 00:00:00')), **{period:1})
+    end = addToDate(DateTime('%s/%s/%s 00:00:00 %s' % (date.year(), zfill(date.month(), 2), zfill(date.day(), 2), date.timezone())), **{period:1})
   elif period == 'week':
     day_of_week = date.strftime('%A')
-    end = DateTime(date.strftime('%Y/%m/%d 00:00:00'))
+    end = DateTime('%s/%s/%s 00:00:00 %s' % (date.year(), zfill(date.month(), 2), zfill(date.day(), 2), date.timezone()))
     while day_of_week != 'Sunday':
       end = addToDate(end, day=1)
       day_of_week = end.strftime('%A')
-- 
2.30.9