summaryrefslogtreecommitdiffstats
path: root/Lib/_strptime.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2003-05-11 06:23:36 (GMT)
committerBrett Cannon <bcannon@gmail.com>2003-05-11 06:23:36 (GMT)
commit172d9ef47eafe6982c2c885353af761256e7b409 (patch)
tree145629dd55cb43474872592c82194da5cc6e16ed /Lib/_strptime.py
parentc2409b4f5a9158bd11999c5c210c7533e576dc42 (diff)
downloadcpython-172d9ef47eafe6982c2c885353af761256e7b409.zip
cpython-172d9ef47eafe6982c2c885353af761256e7b409.tar.gz
cpython-172d9ef47eafe6982c2c885353af761256e7b409.tar.bz2
Beefed up timezone support. UTC and GMT are now always recognized timezones
with values of 0. Also now check time.daylight to see if time.tzname[1] should be used in timezone checking.
Diffstat (limited to 'Lib/_strptime.py')
-rw-r--r--Lib/_strptime.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index 4b7a7dd..a08a426 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -283,9 +283,13 @@ class LocaleTime(object):
def __calc_timezone(self):
# Set self.__timezone by using time.tzname.
#
- # Empty string used for matching when timezone is not used/needed such
- # as with UTC.
- self.__timezone = self.__pad(time.tzname, 0)
+ # Empty string used for matching when timezone is not used/needed.
+ time_zones = ["UTC", "GMT"]
+ if time.daylight:
+ time_zones.extend(time.tzname)
+ else:
+ time_zones.append(time.tzname[0])
+ self.__timezone = self.__pad(time_zones, 0)
def __calc_lang(self):
# Set self.__lang by using __getlang().
@@ -490,16 +494,20 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
elif group_key == 'j':
julian = int(found_dict['j'])
elif group_key == 'Z':
+ # 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]:
pass #Deals with bad locale setup where timezone info is
# the same; first found on FreeBSD 4.4.
- elif locale_time.timezone[0].lower() == found_zone:
+ elif found_zone in ("utc", "gmt"):
tz = 0
- elif locale_time.timezone[1].lower() == found_zone:
- tz = 1
elif locale_time.timezone[2].lower() == found_zone:
- tz = -1
+ tz = 0
+ elif time.daylight:
+ if locale_time.timezone[3].lower() == found_zone:
+ tz = 1
+
# Cannot pre-calculate datetime_date() since can change in Julian
#calculation and thus could have different value for the day of the week
#calculation