summaryrefslogtreecommitdiffstats
path: root/pykolab/xml/utils.py
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-08-21 07:14:10 -0400
committerThomas Bruederli <bruederli@kolabsys.com>2014-08-21 07:14:10 -0400
commitc5978eb22295fea9a09066dc177a5d167c58fb2c (patch)
treedab5a544a81dfb3a9a2a6dda34fd5a43fdb88b80 /pykolab/xml/utils.py
parentb87c86a62e3157de9ee17917783f74dc3b0d756c (diff)
downloadpykolab-c5978eb22295fea9a09066dc177a5d167c58fb2c.tar.gz
Make sure created and last-modified dates are saved in UTC; add folder type property to groupware objects
Diffstat (limited to 'pykolab/xml/utils.py')
-rw-r--r--pykolab/xml/utils.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index bcaa480..aa05e11 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -62,10 +62,18 @@ def from_cdatetime(_cdatetime, with_timezone=True):
return datetime.datetime(year, month, day, hour, minute, second)
-def to_cdatetime(_datetime, with_timezone=True):
+def to_cdatetime(_datetime, with_timezone=True, as_utc=False):
"""
Convert a datetime.dateime object into a kolabformat.cDateTime instance
"""
+ # convert date into UTC timezone
+ if as_utc and hasattr(_datetime, "tzinfo"):
+ if _datetime.tzinfo is not None:
+ _datetime = _datetime.astimezone(pytz.utc)
+ else:
+ datetime = _datetime.replace(tzinfo=pytz.utc)
+ with_timezone = False
+
(
year,
month,
@@ -97,4 +105,7 @@ def to_cdatetime(_datetime, with_timezone=True):
else:
_cdatetime.setTimezone(_datetime.tzinfo.__str__())
+ if as_utc:
+ _cdatetime.setUTC(True)
+
return _cdatetime