datetime_ = datetime
time_ = time
-def get_timezone(zone):
+def get_timezone(zone=None):
"""Looks up a timezone by name and returns it. The timezone object
returned comes from ``pytz`` and corresponds to the `tzinfo` interface and
can be used with all of the functions of Babel that operate with dates.
except _pytz.UnknownTimeZoneError:
raise LookupError('Unknown timezone %s' % zone)
-def get_next_timezone_transition(zone, dt=None):
+def get_next_timezone_transition(zone=None, dt=None):
"""Given a timezone it will return a :class:`TimezoneTransition` object
that holds the information about the next timezone transition that's going
to happen. For instance this can be used to detect when the next DST
if not hasattr(zone, '_utc_transition_times'):
raise TypeError('Given timezone does not have UTC transition '
'times. This can happen because the operating '
- 'system local timezone is used of a custom '
- 'timezone object')
+ 'system fallback local timezone is used or a '
+ 'custom timezone object')
try:
idx = max(0, bisect_right(zone._utc_transition_times, dt))
tt = time.localtime(stamp)
return tt.tm_isdst > 0
+
def get_localzone():
"""Returns the current underlying local timezone object.
Generally this function does not need to be used, it's a
return _get_localzone()
-LOCALTZ = get_localzone()
+try:
+ LOCALTZ = get_localzone()
+except pytz.UnknownTimeZoneError:
+ LOCALTZ = _FallbackLocalTimezone()
import pytz
-tznames = get_global('windows_zone_mapping')
+tz_names = get_global('windows_zone_mapping')
def valuestodict(key):
dict[data[0]] = data[1]
return dict
+
def get_localzone_name():
# Windows is special. It has unique time zone names (in several
# meanings of the word) available, but unfortunately, they can be
def _get_localzone():
+ if winreg is None:
+ raise pytz.UnknownTimeZoneError(
+ 'Runtime support not available')
return pytz.timezone(get_localzone_name())