diff -r 000000000000 -r 712d20d2751e ztfy/utils/timezone.py --- /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 +# 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)