[Python-Dev] RE: [Python-checkins] python/dist/src/Lib _strptime.py, 1.35, 1.36

Index: _strptime.py [...] + # For some reason when Dec 31 falls on a Monday the week of the year is + # off by a week; verified on both OS X and Solaris. + elif weekday == 0 and week_of_year_start == 6 and week_of_year >= 52: + week_of_year += 1
Is this right? At the moment, if I ask for Monday in the 52nd week of 2008, I get the 5th of January 2009:
time.strptime("2008 52 1", "%Y %U %w") (2009, 1, 5, 0, 0, 0, 0, 371, -1)
For reference, Monday in the previous week is the 22nd of December:
time.strptime("2008 51 1", "%Y %U %w") (2008, 12, 22, 0, 0, 0, 0, 357, -1)
Wouldn't December 29 2008 be the right answer? This is the result without that if:
time.strptime("2008 52 1", "%Y %U %w") (2008, 12, 29, 0, 0, 0, 0, 364, -1)
This is with WinXP SP1. =Tony Meyer

Tony Meyer wrote:
Index: _strptime.py
[...]
+ # For some reason when Dec 31 falls on a Monday the week of the year is + # off by a week; verified on both OS X and Solaris. + elif weekday == 0 and week_of_year_start == 6 and week_of_year >= 52: + week_of_year += 1
Is this right? At the moment, if I ask for Monday in the 52nd week of 2008, I get the 5th of January 2009:
time.strptime("2008 52 1", "%Y %U %w")
(2009, 1, 5, 0, 0, 0, 0, 371, -1)
For reference, Monday in the previous week is the 22nd of December:
time.strptime("2008 51 1", "%Y %U %w")
(2008, 12, 22, 0, 0, 0, 0, 357, -1)
Wouldn't December 29 2008 be the right answer? This is the result without that if:
time.strptime("2008 52 1", "%Y %U %w")
(2008, 12, 29, 0, 0, 0, 0, 364, -1)
Can you file a bug report about this? And the test case I was using that triggered the need for that is 1906-12-31 which is a Monday but changes what week it is based on whether you use U or W. which makes no sense since both U and W should consider it the same week. Had the same result for 1917-12-31. -Brett

Tony Meyer wrote:
Index: _strptime.py
[...]
+ # For some reason when Dec 31 falls on a Monday the week of the year is + # off by a week; verified on both OS X and Solaris. + elif weekday == 0 and week_of_year_start == 6 and week_of_year >= 52: + week_of_year += 1
Is this right? At the moment, if I ask for Monday in the 52nd week of 2008, I get the 5th of January 2009:
time.strptime("2008 52 1", "%Y %U %w")
(2009, 1, 5, 0, 0, 0, 0, 371, -1)
For reference, Monday in the previous week is the 22nd of December:
time.strptime("2008 51 1", "%Y %U %w")
(2008, 12, 22, 0, 0, 0, 0, 357, -1)
Wouldn't December 29 2008 be the right answer? This is the result without that if:
Yes, according to the Python documentation. You should however be aware that this is different from the standard (ISO 8601:2000). According to that standard, Monday, week 52, 2008 is December 22. Implementing a function that gives result different from what people actually use is not very good. It is better to leave it unimplemented. = Erik Andersen
time.strptime("2008 52 1", "%Y %U %w")
(2008, 12, 29, 0, 0, 0, 0, 364, -1)
This is with WinXP SP1.
=Tony Meyer
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-erik%40rixmail.se

Erik Andersén wrote:
Tony Meyer wrote:
time.strptime("2008 51 1", "%Y %U %w")
(2008, 12, 22, 0, 0, 0, 0, 357, -1)
Wouldn't December 29 2008 be the right answer? This is the result without that if:
Yes, according to the Python documentation. You should however be aware that this is different from the standard (ISO 8601:2000). According to that standard, Monday, week 52, 2008 is December 22. Implementing a function that gives result different from what people actually use is not very good. It is better to leave it unimplemented.
The function has a bug and is not trying to implement something other than what people are expecting. Having a Julian date that is out of range is my fault in the algorithm and in no way would happen if you passed it in directly. And any more discussion on this bug or this algorithm should go on the bug report (http://www.python.org/sf/1045381) and not on python-dev. -Brett
participants (3)
-
Brett C.
-
Erik Andersén
-
Tony Meyer