Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

The results from ruby are the same as Python master as a data point. From the 
docs 

%U - Week number of the year (Sunday as the first day of the week) as a zero 
padded decimal number. All days in a new year preceding the first Sunday are 
considered to be in week 0.
%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.
%w - Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.

So with 51 (%U) strptime is returning week number 51 of the year (51st sunday, 
23/12/2018) with Sunday as the first day of the week and with %w (first weekday 
with 0 as Sunday) as 0 it returns 23/12/2018 which is the first sunday. With 51 
(%W) strptime is returning week number 51 of the year with Monday (51st Monday, 
17/12/2018) as the first day of the week (2018 starts with Monday) and hence 
with %w as 0 it returns the next sunday (23/12/2018) as first weekday (sunday). 
Where it goes little counter-intuitive is time.strptime('51 1 2018',"%W %w %Y") 
returns 17/12/2018, Monday of the 51st monday as week number that returns the 
17/12/2018 but time.strptime('51 0 2018',"%W %w %Y") returns 23/12/2018 so 
first weekday is higher than the second weekday.

CPython master

$ ./python.exe
Python 3.8.0a0 (heads/master:1dd035954b, Dec 18 2018, 10:12:34)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> dw='51 0 18'
>>> time.strptime(dw,"%U %w %y")
time.struct_time(tm_year=2018, tm_mon=12, tm_mday=23, tm_hour=0, tm_min=0, 
tm_sec=0, tm_wday=6, tm_yday=357, tm_isdst=-1)
>>> time.strptime(dw,"%W %w %y")
time.struct_time(tm_year=2018, tm_mon=12, tm_mday=23, tm_hour=0, tm_min=0, 
tm_sec=0, tm_wday=6, tm_yday=357, tm_isdst=-1)
>>> time.strptime(dw,"%U %w %y") == time.strptime(dw,"%W %w %y")
True

Ruby

$ irb
irb(main):001:0> require 'date'
=> true
irb(main):002:0> DateTime::strptime("51 0 18", "%W %w %y")
=> #<DateTime: 2018-12-23T00:00:00+00:00 ((2458476j,0s,0n),+0s,2299161j)>
irb(main):003:0> DateTime::strptime("51 0 18", "%U %w %y")
=> #<DateTime: 2018-12-23T00:00:00+00:00 ((2458476j,0s,0n),+0s,2299161j)>
irb(main):004:0> DateTime::strptime("51 0 18", "%U %w %y") == 
DateTime::strptime("51 0 18", "%W %w %y")
=> true

----------
nosy: +belopolsky, p-ganssle, xtreak

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

Reply via email to