Accepted None in tzname().
This is required by the tzinfo API, see Python's docs. Also made _get_timezone_name deterministic.
This commit is contained in:
parent
7db770b013
commit
5a3d9490f1
|
@ -80,7 +80,8 @@ class LocalTimezone(tzinfo):
|
||||||
return ZERO
|
return ZERO
|
||||||
|
|
||||||
def tzname(self, dt):
|
def tzname(self, dt):
|
||||||
return _time.tzname[self._isdst(dt)]
|
is_dst = False if dt is None else self._isdst(dt)
|
||||||
|
return _time.tzname[is_dst]
|
||||||
|
|
||||||
def _isdst(self, dt):
|
def _isdst(self, dt):
|
||||||
tt = (dt.year, dt.month, dt.day,
|
tt = (dt.year, dt.month, dt.day,
|
||||||
|
@ -145,8 +146,7 @@ def _get_timezone_name(timezone):
|
||||||
return timezone.zone
|
return timezone.zone
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# for regular tzinfo objects
|
# for regular tzinfo objects
|
||||||
local_now = datetime.now(timezone)
|
return timezone.tzname(None)
|
||||||
return timezone.tzname(local_now)
|
|
||||||
|
|
||||||
# Timezone selection functions.
|
# Timezone selection functions.
|
||||||
|
|
||||||
|
|
|
@ -71,9 +71,9 @@ class LocalTimezone(tzinfo):
|
||||||
return timedelta(0)
|
return timedelta(0)
|
||||||
|
|
||||||
def tzname(self, dt):
|
def tzname(self, dt):
|
||||||
|
is_dst = False if dt is None else self._isdst(dt)
|
||||||
try:
|
try:
|
||||||
return force_text(time.tzname[self._isdst(dt)],
|
return force_text(time.tzname[is_dst], DEFAULT_LOCALE_ENCODING)
|
||||||
DEFAULT_LOCALE_ENCODING)
|
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue