Project

General

Profile

Actions

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.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:74454]

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.

Updated by zverok (Victor Shepelev) about 8 years ago

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.

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

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.

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Status changed from Open to Closed

The pull request was merged.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0