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.common.idatetime import ITZInfo |
|
28 from zope.publisher.interfaces.browser import IBrowserRequest |
|
29 |
|
30 # import local interfaces |
|
31 |
|
32 # import Zope3 packages |
|
33 from zope.component import adapter |
|
34 from zope.interface import implementer |
|
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 @adapter(IBrowserRequest) |
|
45 def tzinfo(request=None): |
|
46 return tz |
|
47 |
|
48 |
|
49 def tztime(value): |
|
50 if not value: |
|
51 return None |
|
52 if not value.tzinfo: |
|
53 value = GMT.localize(value) |
|
54 return value.astimezone(tz) |
|
55 |
|
56 |
|
57 def gmtime(value): |
|
58 if not value: |
|
59 return None |
|
60 if not value.tzinfo: |
|
61 value = GMT.localize(value) |
|
62 return value.astimezone(GMT) |
|