ztfy/utils/timezone.py
changeset 0 712d20d2751e
child 8 455b16a502c4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ztfy/utils/timezone.py	Sat Jan 10 00:35:35 2009 +0100
@@ -0,0 +1,58 @@
+##############################################################################
+#
+# Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id: $
+"""
+
+__version__   = "$Revision: $"
+__release__   = "$Id: $"
+__docformat__ = "restructuredtext"
+
+# import standard packages
+import pytz
+
+# import Zope3 interfaces
+from zope.interface import implementer
+from zope.interface.common.idatetime import ITZInfo
+from zope.publisher.interfaces.browser import IBrowserRequest
+
+# import local interfaces
+
+# import Zope3 packages
+from zope import component
+
+# import local packages
+
+
+GMT = pytz.timezone('GMT')
+_tz = pytz.timezone('Europe/Paris')
+tz = _tz
+
+@implementer(ITZInfo)
+@component.adapter(IBrowserRequest)
+def tzinfo(request=None):
+     return tz
+
+
+def tztime(value):
+    if not value.tzinfo:
+        value = GMT.localize(value)
+    return value.astimezone(tz)
+
+
+def gmtime(value):
+    if not value.tzinfo:
+        value = GMT.localize(value)
+    return value.astimezone(GMT)