diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-12 08:51:16 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-12 08:51:16 (GMT) |
commit | 5c2cb824f4e9ec02af2424af09c9f692f548aed5 (patch) | |
tree | 5a1f3de9715a5ddf16cf2156305662918ee68a24 | |
parent | ca7610020560bc1b1fbf3a062eeea075af2596ca (diff) | |
download | cpython-5c2cb824f4e9ec02af2424af09c9f692f548aed5.zip cpython-5c2cb824f4e9ec02af2424af09c9f692f548aed5.tar.gz cpython-5c2cb824f4e9ec02af2424af09c9f692f548aed5.tar.bz2 |
Issue #23718: Fixed parsing time in week 0 before Jan 1. Original patch by
Tamás Bence Gedai.
-rw-r--r-- | Lib/_strptime.py | 4 | ||||
-rw-r--r-- | Lib/test/test_strptime.py | 28 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 29 insertions, 7 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py index 63dca02..feac05a 100644 --- a/Lib/_strptime.py +++ b/Lib/_strptime.py @@ -445,6 +445,10 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"): week_starts_Mon = True if week_of_year_start == 0 else False julian = _calc_julian_from_U_or_W(year, week_of_year, weekday, week_starts_Mon) + if julian <= 0: + year -= 1 + yday = 366 if calendar.isleap(year) else 365 + julian += yday # Cannot pre-calculate datetime_date() since can change in Julian # calculation and thus could have different value for the day of the week # calculation. diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py index a3ab426..3d24941 100644 --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -486,14 +486,14 @@ class CalculationTests(unittest.TestCase): def test_week_0(self): def check(value, format, *expected): self.assertEqual(_strptime._strptime_time(value, format)[:-1], expected) - check('2015 0 0', '%Y %U %w', 2014, 12, 28, 0, 0, 0, 6, -3) + check('2015 0 0', '%Y %U %w', 2014, 12, 28, 0, 0, 0, 6, 362) check('2015 0 0', '%Y %W %w', 2015, 1, 4, 0, 0, 0, 6, 4) - check('2015 0 1', '%Y %U %w', 2014, 12, 29, 0, 0, 0, 0, -2) - check('2015 0 1', '%Y %W %w', 2014, 12, 29, 0, 0, 0, 0, -2) - check('2015 0 2', '%Y %U %w', 2014, 12, 30, 0, 0, 0, 1, -1) - check('2015 0 2', '%Y %W %w', 2014, 12, 30, 0, 0, 0, 1, -1) - check('2015 0 3', '%Y %U %w', 2014, 12, 31, 0, 0, 0, 2, 0) - check('2015 0 3', '%Y %W %w', 2014, 12, 31, 0, 0, 0, 2, 0) + check('2015 0 1', '%Y %U %w', 2014, 12, 29, 0, 0, 0, 0, 363) + check('2015 0 1', '%Y %W %w', 2014, 12, 29, 0, 0, 0, 0, 363) + check('2015 0 2', '%Y %U %w', 2014, 12, 30, 0, 0, 0, 1, 364) + check('2015 0 2', '%Y %W %w', 2014, 12, 30, 0, 0, 0, 1, 364) + check('2015 0 3', '%Y %U %w', 2014, 12, 31, 0, 0, 0, 2, 365) + check('2015 0 3', '%Y %W %w', 2014, 12, 31, 0, 0, 0, 2, 365) check('2015 0 4', '%Y %U %w', 2015, 1, 1, 0, 0, 0, 3, 1) check('2015 0 4', '%Y %W %w', 2015, 1, 1, 0, 0, 0, 3, 1) check('2015 0 5', '%Y %U %w', 2015, 1, 2, 0, 0, 0, 4, 2) @@ -501,6 +501,20 @@ class CalculationTests(unittest.TestCase): check('2015 0 6', '%Y %U %w', 2015, 1, 3, 0, 0, 0, 5, 3) check('2015 0 6', '%Y %W %w', 2015, 1, 3, 0, 0, 0, 5, 3) + check('2009 0 0', '%Y %U %w', 2008, 12, 28, 0, 0, 0, 6, 363) + check('2009 0 0', '%Y %W %w', 2009, 1, 4, 0, 0, 0, 6, 4) + check('2009 0 1', '%Y %U %w', 2008, 12, 29, 0, 0, 0, 0, 364) + check('2009 0 1', '%Y %W %w', 2008, 12, 29, 0, 0, 0, 0, 364) + check('2009 0 2', '%Y %U %w', 2008, 12, 30, 0, 0, 0, 1, 365) + check('2009 0 2', '%Y %W %w', 2008, 12, 30, 0, 0, 0, 1, 365) + check('2009 0 3', '%Y %U %w', 2008, 12, 31, 0, 0, 0, 2, 366) + check('2009 0 3', '%Y %W %w', 2008, 12, 31, 0, 0, 0, 2, 366) + check('2009 0 4', '%Y %U %w', 2009, 1, 1, 0, 0, 0, 3, 1) + check('2009 0 4', '%Y %W %w', 2009, 1, 1, 0, 0, 0, 3, 1) + check('2009 0 5', '%Y %U %w', 2009, 1, 2, 0, 0, 0, 4, 2) + check('2009 0 5', '%Y %W %w', 2009, 1, 2, 0, 0, 0, 4, 2) + check('2009 0 6', '%Y %U %w', 2009, 1, 3, 0, 0, 0, 5, 3) + check('2009 0 6', '%Y %W %w', 2009, 1, 3, 0, 0, 0, 5, 3) class CacheTests(unittest.TestCase): """Test that caching works properly.""" @@ -466,6 +466,7 @@ Matthieu Gautier Stephen M. Gava Xavier de Gaye Harry Henry Gebel +Tamás Bence Gedai Marius Gedminas Thomas Gellekum Gabriel Genellina @@ -58,6 +58,9 @@ Core and Builtins Library ------- +- Issue #23718: Fixed parsing time in week 0 before Jan 1. Original patch by + Tamás Bence Gedai. + - Issue #26177: Fixed the keys() method for Canvas and Scrollbar widgets. - Issue #15068: Got rid of excessive buffering in the fileinput module. |