ztfy/utils/timezone.py
changeset 0 712d20d2751e
child 8 455b16a502c4
equal deleted inserted replaced
-1:000000000000 0:712d20d2751e
       
     1 ##############################################################################
       
     2 #
       
     3 # Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
       
     4 # All Rights Reserved.
       
     5 #
       
     6 # This software is subject to the provisions of the Zope Public License,
       
     7 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    11 # FOR A PARTICULAR PURPOSE.
       
    12 #
       
    13 ##############################################################################
       
    14 """
       
    15 
       
    16 $Id: $
       
    17 """
       
    18 
       
    19 __version__   = "$Revision: $"
       
    20 __release__   = "$Id: $"
       
    21 __docformat__ = "restructuredtext"
       
    22 
       
    23 # import standard packages
       
    24 import pytz
       
    25 
       
    26 # import Zope3 interfaces
       
    27 from zope.interface import implementer
       
    28 from zope.interface.common.idatetime import ITZInfo
       
    29 from zope.publisher.interfaces.browser import IBrowserRequest
       
    30 
       
    31 # import local interfaces
       
    32 
       
    33 # import Zope3 packages
       
    34 from zope import component
       
    35 
       
    36 # import local packages
       
    37 
       
    38 
       
    39 GMT = pytz.timezone('GMT')
       
    40 _tz = pytz.timezone('Europe/Paris')
       
    41 tz = _tz
       
    42 
       
    43 @implementer(ITZInfo)
       
    44 @component.adapter(IBrowserRequest)
       
    45 def tzinfo(request=None):
       
    46      return tz
       
    47 
       
    48 
       
    49 def tztime(value):
       
    50     if not value.tzinfo:
       
    51         value = GMT.localize(value)
       
    52     return value.astimezone(tz)
       
    53 
       
    54 
       
    55 def gmtime(value):
       
    56     if not value.tzinfo:
       
    57         value = GMT.localize(value)
       
    58     return value.astimezone(GMT)