This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jamercee
Recipients jamercee
Date 2014-12-30.21:04:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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()
..., 1, 4), 12, 29), 1, 1)   # <-- ERROR: should be '2014, 12, 30', 12, 31), 1, 1), 1, 2), 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
Date User Action Args
2014-12-30 21:04:37jamerceesetrecipients: + jamercee
2014-12-30 21:04:37jamerceesetmessageid: <>
2014-12-30 21:04:37jamerceelinkissue23136 messages
2014-12-30 21:04:36jamerceecreate