Bug #12196
closed
lib: Date.valid_date? returns incorrect response for negative day
Added by ddoherty03 (Daniel Doherty) about 8 years ago.
Updated almost 5 years ago.
Description
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.
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.
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.
I don't think this is a bug in the code, but I do think we should improve the documentation for valid_date. I've added a pull request to do so: https://github.com/ruby/date/pull/7.
- Status changed from Open to Closed
The pull request was merged.
Also available in: Atom
PDF
Like0
Like0Like0Like0