Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

cpython (merge 3.2 -> default): Issue #14157: Fix time.strptime failing without a year on February 29th.

 

 

Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

May 10, 2012, 11:20 AM

Post #1 of 1 (79 views)
Permalink
cpython (merge 3.2 -> default): Issue #14157: Fix time.strptime failing without a year on February 29th.

http://hg.python.org/cpython/rev/a5a254e8a291
changeset: 76865:a5a254e8a291
parent: 76863:99ef4501205b
parent: 76864:f2ea7505c0d7
user: Antoine Pitrou <solipsis [at] pitrou>
date: Thu May 10 20:18:46 2012 +0200
summary:
Issue #14157: Fix time.strptime failing without a year on February 29th.
Patch by Hynek Schlawack.

files:
Lib/_strptime.py | 6 +++++-
Lib/test/test_strptime.py | 3 +++
Misc/NEWS | 3 +++
3 files changed, 11 insertions(+), 1 deletions(-)


diff --git a/Lib/_strptime.py b/Lib/_strptime.py
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -339,7 +339,7 @@
raise ValueError("unconverted data remains: %s" %
data_string[found.end():])

- year = 1900
+ year = None
month = day = 1
hour = minute = second = fraction = 0
tz = -1
@@ -444,6 +444,10 @@
else:
tz = value
break
+ if year is None and month == 2 and day == 29:
+ year = 1904 # 1904 is first leap year of 20th century
+ elif year is None:
+ year = 1900
# If we know the week of the year and what day of that week, we can figure
# out the Julian day of the year.
if julian == -1 and week_of_year != -1 and weekday != -1:
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py
--- a/Lib/test/test_strptime.py
+++ b/Lib/test/test_strptime.py
@@ -378,6 +378,9 @@
need_escaping = ".^$*+?{}\[]|)("
self.assertTrue(_strptime._strptime_time(need_escaping, need_escaping))

+ def test_feb29_on_leap_year_without_year(self):
+ time.strptime("Feb 29", "%b %d")
+
class Strptime12AMPMTests(unittest.TestCase):
"""Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""

diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,9 @@
Library
-------

+- Issue #14157: Fix time.strptime failing without a year on February 29th.
+ Patch by Hynek Schlawack.
+
- Issue #14753: Make multiprocessing's handling of negative timeouts
the same as it was in Python 3.2.


--
Repository URL: http://hg.python.org/cpython

Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.