# Since -1 is default value only need to worry about setting tz if
# it can be something other than -1.
found_zone = found_dict['Z'].lower()
- if locale_time.timezone[0] == locale_time.timezone[1] and \
- time.daylight:
- pass #Deals with bad locale setup where timezone info is
- # the same; first found on FreeBSD 4.4.
- elif found_zone in ("utc", "gmt"):
+ if found_zone in ("utc", "gmt"):
tz = 0
+ elif time.tzname[0] == time.tzname[1] and \
+ time.daylight:
+ continue #Deals with bad locale setup where timezone info is
+ # the same; first found on FreeBSD 4.4.
elif locale_time.timezone[2].lower() == found_zone:
tz = 0
elif time.daylight and \
"LocaleTime().timezone has duplicate values and "
"time.daylight but timezone value not set to -1")
+ def test_bad_timezone(self):
+ # Explicitly test possibility of bad timezone;
+ # when time.tzname[0] == time.tzname[1] and time.daylight
+ if sys.platform == "mac":
+ return # MacOS9 has severely broken timezone support.
+ try:
+ original_tzname = time.tzname
+ original_daylight = time.daylight
+ time.tzname = ("PDT", "PDT")
+ time.daylight = 1
+ # Need to make sure that timezone is not calculated since that
+ # calls time.tzset and overrides temporary changes to time .
+ _strptime._locale_cache = _strptime.TimeRE(_strptime.LocaleTime(
+ timezone=("PDT", "PDT")))
+ _strptime._regex_cache.clear()
+ tz_value = _strptime.strptime("PDT", "%Z")[8]
+ self.failUnlessEqual(tz_value, -1)
+ finally:
+ time.tzname = original_tzname
+ time.daylight = original_daylight
+ _strptime._locale_cache = _strptime.TimeRE()
+ _strptime._regex_cache.clear()
+
def test_date_time(self):
# Test %c directive
for position in range(6):