[ruby-core:74455] [Ruby trunk Bug#12196] lib: Date.valid_date? returns incorrect response for negative day

From: zverok.offline@...
Date: 2016-03-18 13:24:10 UTC
List: ruby-core #74455
Issue #12196 has been updated by Victor Shepelev.


From `Date::new` docs:

>  The month and the day of month **should be a negative or a positive number** (as a relative month/day from the end of year/month when negative). They should not be zero.

~~~ruby
Date.new(2016,2,-1)
# => #<Date: 2016-02-29 ((2457448j,0s,0n),+0s,2299161j)>
~~~

From `Date.valid_date?` docs:

> Returns true if the given calendar date is valid, and false if not.

The latter is pretty brief, yet I assume it means rather "valid params for Date.new" than anything else.

----------------------------------------
Bug #12196: lib: Date.valid_date? returns incorrect response for negative day
https://bugs.ruby-lang.org/issues/12196#change-57575

* Author: Daniel Doherty
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.2.2
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
~~~
require 'date'
puts RUBY_VERSION
if Date.valid_date?(2016, 2, -1)
  puts "Valid"
else
  puts "Invalid"
end
~~~

This reports 'Valid' for a negative day number.




-- 
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>

In This Thread

Prev Next