Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8a7240ee
Commit
8a7240ee
authored
Mar 12, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23718: Fixed parsing time in week 0 before Jan 1. Original patch by
Tamás Bence Gedai.
parent
d7569637
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
7 deletions
+29
-7
Lib/_strptime.py
Lib/_strptime.py
+4
-0
Lib/test/test_strptime.py
Lib/test/test_strptime.py
+21
-7
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/_strptime.py
View file @
8a7240ee
...
...
@@ -462,6 +462,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.
...
...
Lib/test/test_strptime.py
View file @
8a7240ee
...
...
@@ -496,14 +496,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)
...
...
@@ -511,6 +511,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."""
...
...
Misc/ACKS
View file @
8a7240ee
...
...
@@ -484,6 +484,7 @@ Matthieu Gautier
Stephen M. Gava
Xavier de Gaye
Harry Henry Gebel
Tamás Bence Gedai
Marius Gedminas
Jan-Philip Gehrcke
Thomas Gellekum
...
...
Misc/NEWS
View file @
8a7240ee
...
...
@@ -91,6 +91,9 @@ Core and Builtins
Library
-------
- Issue #23718: Fixed parsing time in week 0 before Jan 1. Original patch by
Tamás Bence Gedai.
- Issue #20589: Invoking Path.owner() and Path.group() on Windows now raise
NotImplementedError instead of ImportError.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment