Author jamercee
Recipients jamercee
Date 2014-12-30.21:04:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1419973477.15.0.355513795882.issue23136@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2014-12-30 21:04:37jamerceesetrecipients: + jamercee
2014-12-30 21:04:37jamerceesetmessageid: <1419973477.15.0.355513795882.issue23136@psf.upfronthosting.co.za>
2014-12-30 21:04:37jamerceelinkissue23136 messages
2014-12-30 21:04:36jamerceecreate