End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Date.valid_civil?
Date.valid_civil?(year, month, mday[, start=Date::ITALY]) → bool
Date.valid_date?(year, month, mday[, start=Date::ITALY]) → bool
ext/date/date_core.c
View on GitHub ↗
static VALUE
date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
{
VALUE vy, vm, vd, vsg;
VALUE argv2[4];
rb_scan_args(argc, argv, "31", &vy, &vm, &vd, &vsg);
RETURN_FALSE_UNLESS_NUMERIC(vy);
RETURN_FALSE_UNLESS_NUMERIC(vm);
RETURN_FALSE_UNLESS_NUMERIC(vd);
argv2[0] = vy;
argv2[1] = vm;
argv2[2] = vd;
if (argc < 4)
argv2[3] = INT2FIX(DEFAULT_SG);
else
argv2[3] = vsg;
if (NIL_P(valid_civil_sub(4, argv2, klass, 0)))
return Qfalse;
return Qtrue;
}
Returns true if the given calendar date is valid, and false if not. Valid in this context is whether the arguments passed to this method would be accepted by ::new.
Example
Date.valid_date?(2001,2,3) #=> true Date.valid_date?(2001,2,29) #=> false Date.valid_date?(2001,2,-1) #=> true
See also
.today
.valid_commercial?
.test_weeknum
.valid_date?
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0