1 """tzinfo implementations for psycopg2
2
3 This module holds two different tzinfo implementations that can be used as
4 the 'tzinfo' argument to datetime constructors, directly passed to psycopg
5 functions or used to set the .tzinfo_factory attribute in cursors.
6 """
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import datetime
22 import time
23
24
25 ZERO = datetime.timedelta(0)
26
28 """Fixed offset in minutes east from UTC.
29
30 This is exactly the implementation found in Python 2.3.x documentation,
31 with a small change to the __init__ method to allow for pickling and a
32 default name in the form 'sHH:MM' ('s' is the sign.)
33 """
34 _name = None
35 _offset = ZERO
36
37 - def __init__(self, offset=None, name=None):
42
45
57
60
61
62 STDOFFSET = datetime.timedelta(seconds = -time.timezone)
63 if time.daylight:
64 DSTOFFSET = datetime.timedelta(seconds = -time.altzone)
65 else:
66 DSTOFFSET = STDOFFSET
67 DSTDIFF = DSTOFFSET - STDOFFSET
68
70 """Platform idea of local timezone.
71
72 This is the exact implementation from the Pyhton 2.3 documentation.
73 """
74
80
82 if self._isdst(dt):
83 return DSTDIFF
84 else:
85 return ZERO
86
88 return time.tzname[self._isdst(dt)]
89
91 tt = (dt.year, dt.month, dt.day,
92 dt.hour, dt.minute, dt.second,
93 dt.weekday(), 0, -1)
94 stamp = time.mktime(tt)
95 tt = time.localtime(stamp)
96 return tt.tm_isdst > 0
97
98 LOCAL = LocalTimezone()
99
100
101