Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,9 @@ def parse_int(s):
datetime_result = datetime_date.fromordinal(
(julian - 1) +
datetime_date(year, 1, 1).toordinal())
if year != datetime_result.year:
year_start = datetime_date(datetime_result.year, 1, 1)
julian = datetime_result.toordinal() - year_start.toordinal() + 1
year = datetime_result.year
month = datetime_result.month
day = datetime_result.day
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,18 @@ def check(value, format, *expected):
check('2009 0 6', '%Y %W %w', 2009, 1, 3, 0, 0, 0, 5, 3)
check('2009 1 7', '%G %V %u', 2009, 1, 4, 0, 0, 0, 6, 4)

def test_julian_day_next_year(self):
for value, format, expected in (
('2016 52 0', '%Y %W %w', (2017, 1, 1, 6, 1)),
('2015 52 5', '%Y %U %w', (2016, 1, 1, 4, 1)),
('2019 366', '%Y %j', (2020, 1, 1, 2, 1)),
):
with self.subTest(value=value, format=format):
result = time.strptime(value, format)
self.assertEqual(
(result.tm_year, result.tm_mon, result.tm_mday,
result.tm_wday, result.tm_yday), expected)


class CacheTests(unittest.TestCase):
"""Test that caching works properly."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`time.strptime` returning an inconsistent day of year when a week
number or ordinal day resolves to a date in the following year.
Loading