Issue #14317 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Rejected

I do not think this is a bug.  It is reasonable for `Date.strptime` to assume a value of 0/Sunday for `:cwday`/`%u` if `:wnum0`/`%U` is specified without `%u`.  In every other case where you specify `%U` without `%u`, you get a Sunday. I don't think it would make sense to be inconsistent and return a non-Sunday date for week 0.

If you really want to handle this differently, use `Date._strptime` and handle the resulting hash specially:

```ruby
Date._strptime("0 2018", "%U %Y")
# => {:wnum0=>0, :year=>2018}

Date._strptime("1 0 2018", "%u %U %Y")
# => {:cwday=>1, :wnum0=>0, :year=>2018}
```


----------------------------------------
Bug #14317: Date.strptime(..., "%U") fails if  first day of the week is not in the 0th week.
https://bugs.ruby-lang.org/issues/14317#change-78765

* Author: jbake (Julien Bake)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Date.new(2018,1,1)
=> Mon, 01 Jan 2018

Date.new(2018,1,1).strftime("%U %Y")
=> "00 2018"

Date.strptime("00 2018", "%U %Y")
ArgumentError: invalid date

 Date.strptime("1 0 2018", "%u %U %Y")
=> Mon, 01 Jan 2018

i would expect to get the first valid date that is in the 0th week (1.1.2018) from Date.strptime("00 2018", "%U %Y") even if the first day (sunday) of the 0th week is not existing / in the last year.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>