New submission from Jim Carroll:

The following bit of code demonstrates a bug in how _strptime handles week 0. 
The bug is an edge condition that specifically affects how it handles two days 
before the first day of the new year

>>> for i in range(7):
...     datetime.strptime('%s %s %s' % (0, 2015, i), '%W %Y %w').date()
... 
datetime.date(2015, 1, 4)
datetime.date(2014, 12, 29)
datetime.date(2015, 1, 1)   # <-- ERROR: should be '2014, 12, 30'
datetime.date(2014, 12, 31)
datetime.date(2015, 1, 1)
datetime.date(2015, 1, 2)
datetime.date(2015, 1, 3)

The issue stems from the fact that calls to _calc_julian_from_U_or_W() can 
return a -1, which under normal circumstances is invalid. The strptime() 
function tests and corrects when julian values are -1...but it should not do 
this when the week_of_year is zero.

The fact that it tests for ONLY -1 is why we see the problem in 2015. The error 
condition only exists when the first day of the year is exactly two days ahead 
of the date being tested for.

Patch is attached

----------
components: Library (Lib)
files: patch.txt
messages: 233219
nosy: jamercee
priority: normal
severity: normal
status: open
title: BUG in how _strptime() handles week 0
versions: Python 2.7
Added file: http://bugs.python.org/file37568/patch.txt

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23136>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to