summaryrefslogtreecommitdiff
path: root/Lib/_strptime.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-05-14 19:44:59 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2012-05-14 19:44:59 +0200
commit1efbbdf38ecc7c91a16308be098d7c8faeb2596f (patch)
treea291ebd8791b6c23cc0593e3c96927e01991ddfa /Lib/_strptime.py
parent2ec60d4030055f9c9af1b62e5a521b66ae349d37 (diff)
downloadcpython-1efbbdf38ecc7c91a16308be098d7c8faeb2596f.tar.gz
Followup to issue #14157: respect the relative ordering of values produced by time.strptime().
Patch by Hynek.
Diffstat (limited to 'Lib/_strptime.py')
-rw-r--r--Lib/_strptime.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index 0106e914ae..fa06376992 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -444,8 +444,10 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
else:
tz = value
break
+ leap_year_fix = False
if year is None and month == 2 and day == 29:
year = 1904 # 1904 is first leap year of 20th century
+ leap_year_fix = True
elif year is None:
year = 1900
# If we know the week of the year and what day of that week, we can figure
@@ -476,6 +478,12 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
else:
gmtoff = None
+ if leap_year_fix:
+ # the caller didn't supply a year but asked for Feb 29th. We couldn't
+ # use the default of 1900 for computations. We set it back to ensure
+ # that February 29th is smaller than March 1st.
+ year = 1900
+
return (year, month, day,
hour, minute, second,
weekday, julian, tz, gmtoff, tzname), fraction