1 # -*- coding: utf-8 -*-
6 Babel specific fork of tzlocal to determine the local timezone
9 :copyright: (c) 2013 by the Babel Team.
10 :license: BSD, see LICENSE for more details.
16 from datetime import timedelta
17 from datetime import tzinfo
18 from threading import RLock
20 if sys.platform == 'win32':
21 from babel.localtime._win32 import _get_localzone
23 from babel.localtime._unix import _get_localzone
29 STDOFFSET = timedelta(seconds=-time.timezone)
31 DSTOFFSET = timedelta(seconds=-time.altzone)
35 DSTDIFF = DSTOFFSET - STDOFFSET
39 class _FallbackLocalTimezone(tzinfo):
41 def utcoffset(self, dt):
54 return time.tzname[self._isdst(dt)]
57 tt = (dt.year, dt.month, dt.day,
58 dt.hour, dt.minute, dt.second,
60 stamp = time.mktime(tt)
61 tt = time.localtime(stamp)
62 return tt.tm_isdst > 0
66 """Returns the current underlying local timezone object.
67 Generally this function does not need to be used, it's a
68 better idea to use the :data:`LOCALTZ` singleton instead.
70 return _get_localzone()
74 LOCALTZ = get_localzone()
75 except pytz.UnknownTimeZoneError:
76 LOCALTZ = _FallbackLocalTimezone()