https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112014-04-21T04:38:03ZRuby Issue Tracking SystemRuby master - Bug #9764: Date and DateTime strptime and strftime not supporting proper Week Numbering for Monday vs Sunday as start day and %G causes ignore of all other format argumentshttps://bugs.ruby-lang.org/issues/9764?journal_id=462702014-04-21T04:38:03ZStephenOTT (Steve R)stephenrussett@gmail.com
<ul></ul><p>Same issue with: ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-darwin12.5.0]</p> Ruby master - Bug #9764: Date and DateTime strptime and strftime not supporting proper Week Numbering for Monday vs Sunday as start day and %G causes ignore of all other format argumentshttps://bugs.ruby-lang.org/issues/9764?journal_id=462742014-04-21T10:48:02Ztadf (tadayoshi funaba)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>tadf (tadayoshi funaba)</i></li><li><strong>Priority</strong> changed from <i>Normal</i> to <i>3</i></li></ul> Ruby master - Bug #9764: Date and DateTime strptime and strftime not supporting proper Week Numbering for Monday vs Sunday as start day and %G causes ignore of all other format argumentshttps://bugs.ruby-lang.org/issues/9764?journal_id=462752014-04-21T11:24:37Ztadf (tadayoshi funaba)
<ul></ul><pre><code>first of all, you have to know there are three systems of week.
the following thee are proper/typical combinatins.
%G %V %u # (I)
%Y %W %u # (E)
%Y %U %w # (R)
strptime try to find other ways, but basically supoorts the above three only.
January 2014 (I)
M Tu W Th F S S
30 31 1 2 3 4 5 # 1st
6 7 8 9 10 11 12 # 2nd
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
January 2014 (E)
M Tu W Th F S S
1 2 3 4 5 # 0th
6 7 8 9 10 11 12 # 1st
13 14 15 16 17 18 19 # 2nd
20 21 22 23 24 25 26
27 28 29 30 31
January 2014 (R)
S M Tu W Th F S
1 2 3 4 # 0th
5 6 7 8 9 10 11 # 1st
12 13 14 15 16 17 18 # 2nd
19 20 21 22 23 24 25
26 27 28 29 30 31
Date.new(2013,12,30).strftime('%G %V %u | %Y %W %u | %Y %U %w') #=> "2014 01 1 | 2013 52 1 | 2013 52 1"
Date.new(2014,1,1). strftime('%G %V %u | %Y %W %u | %Y %U %w') #=> "2014 01 3 | 2014 00 3 | 2014 00 3"
Date.new(2014,1,5). strftime('%G %V %u | %Y %W %u | %Y %U %w') #=> "2014 01 7 | 2014 00 7 | 2014 01 0"
Date.new(2014,1,6). strftime('%G %V %u | %Y %W %u | %Y %U %w') #=> "2014 02 1 | 2014 01 1 | 2014 01 1"
they are different systems.
answer of 1.
it is meaningless.
answer of 2.
%U (and %W) can't align with %G.
so, strptime just ignores %U and completes first day of first week.
Date.strptime("2014","%G") == Date.strptime("2014 01 1","%G %V %u") #=> true
answer of 3.
Date.strptime('00 2014', '%W %Y') # ArgumentError: invalid date
but,
Date.strptime('01 2014', '%W %Y') #=> #<Date: 2014-01-06 ((2456664j,0s,0n),+0s,2299161j)>
Date.strptime('3 00 2014', '%u %W %Y') #=> #<Date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>
why?
since, the 0th monday (= the first day of week) is not exists, not valid.
Date.new(2013,12,30).step(Date.new(2014,1,11)){|d| p d.strftime('%Y %W %u')}
"2013 52 1"
"2013 52 2"
"2014 00 3"
"2014 00 4"
"2014 00 5"
"2014 00 6"
"2014 00 7"
"2014 01 1"
"2014 01 2"
"2014 01 3"
"2014 01 4"
"2014 01 5"
"2014 01 6"
#=> #<Date: 2013-12-30 ((2456657j,0s,0n),+0s,2299161j)>
</code></pre> Ruby master - Bug #9764: Date and DateTime strptime and strftime not supporting proper Week Numbering for Monday vs Sunday as start day and %G causes ignore of all other format argumentshttps://bugs.ruby-lang.org/issues/9764?journal_id=462762014-04-21T11:26:03Ztadf (tadayoshi funaba)
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul> Ruby master - Bug #9764: Date and DateTime strptime and strftime not supporting proper Week Numbering for Monday vs Sunday as start day and %G causes ignore of all other format argumentshttps://bugs.ruby-lang.org/issues/9764?journal_id=462782014-04-21T16:56:30ZStephenOTT (Steve R)stephenrussett@gmail.com
<ul></ul><p>Okay great. Thank you for the quick and detailed response. This seems to be a documentation confusion as we had about 10 people trying this out over a few days and all were confused based on what was in the documentation and the results. I will submit some updated documentation to clarify.</p> Ruby master - Bug #9764: Date and DateTime strptime and strftime not supporting proper Week Numbering for Monday vs Sunday as start day and %G causes ignore of all other format argumentshttps://bugs.ruby-lang.org/issues/9764?journal_id=462792014-04-21T17:03:55ZStephenOTT (Steve R)stephenrussett@gmail.com
<ul></ul><p>@Tadayoshi funaba,</p>
<p>I think i understand part of the issue now related to some of the confusion.</p>
<p>Date.Comercial() allows you to provide the Year and Week number to get a date. It was the expectation that <code>puts Date.strptime('2014 00', '%Y %U' )</code> would generate the same value as .Comercial but with Sunday as the first day of Week.</p>
<p>Is there a way to support .Commercial input arguments with a Sunday first day or week?</p>
<p>The use case is that many systems will return a %U style 0-53 week time grouping (group results by week number). The system returns a Week Number (0-53) integer and a Year integer. You want to convert this into a date for sorting and other benefits, but you do not know the day number.</p>