[issue19774] strptime incorrect for weekday '0' when using week number format

2013-11-25 Thread R. David Murray

R. David Murray added the comment:

from the man page for strptime:

   %w The weekday number (0-6) with Sunday = 0.

   %W The week number with Monday the first day of  the  week  (0-53).
  The first Monday of January is the first day of week 1.

Python's documentation is just a tiny bit clearer about %W:

   %W Week number of the year (Monday as the first day of the week) as 
a decimal number. All days in a new year preceding the first Monday are 
considered to be in week 0.

So, the result is correct, albeit very unintuitive (the week day numbers for 
the purposes of %W are the sequence 1-2-3-4-5-6-0).  You will note that if you 
call strftime with the same format string, you will get your input strings out 
as the output.

Call this a design bug in posix that python has inherited.  You will get the 
exact same behavior if you write a C program that calls strptime/strftime.

--
nosy: +r.david.murray
resolution:  -> invalid
stage:  -> committed/rejected
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19774] strptime incorrect for weekday '0' when using week number format

2013-11-25 Thread Steve J Borba

New submission from Steve J Borba:

OS: Windows 7 Professional (64-bit)
Hardware: Intel

datetime.strptime returns an incorrect value when calculating a date using a 
week number format, such as "%Y-%W-%w" (Year-Week-Weekday). The value returned 
for weekday '0' of a given week is consistently 7 days greater than it should 
be. The following code illustrates:

from datetime import datetime
for i in range(0,53):
if i == 0:
yr=input("Enter a valid year: ")
print("Wk#\tBeginning of week\tEnd of week")
BegWk = datetime.strptime((yr + "-" + str(i) + "-0"),"%Y-%W-%w")
EndWk = datetime.strptime((yr + "-" + str(i) + "-6"),"%Y-%W-%w")
print(str(i) + "\t" + str(BegWk) + "\t" +str(EndWk))

Here is a clip (7 lines) of the output from the code above:
Enter a valid year: 2013
Wk# Beginning of week   End of week
0   2013-01-06 00:00:00 2013-01-05 00:00:00
1   2013-01-13 00:00:00 2013-01-12 00:00:00
2   2013-01-20 00:00:00 2013-01-19 00:00:00
3   2013-01-27 00:00:00 2013-01-26 00:00:00
4   2013-02-03 00:00:00 2013-02-02 00:00:00
5   2013-02-10 00:00:00 2013-02-09 00:00:00
6   2013-02-17 00:00:00 2013-02-16 00:00:00

The value returned for the first column of each week is exactly 7 days higher 
than the correct result.

--
components: Library (Lib)
messages: 204382
nosy: Steve.J.Borba
priority: normal
severity: normal
status: open
title: strptime incorrect for weekday '0' when using week number format
type: behavior
versions: Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com