Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Date.valid_date?
(::Integer year, ::Integer month, ::Integer mday, ?::Integer start) -> bool
Date.valid_civil?(year, month, mday, start = Date::ITALY) → true or false
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 arguments define a valid ordinal date, false otherwise:
Example
Date.valid_date?(2001, 2, 3) # => true Date.valid_date?(2001, 2, 29) # => false Date.valid_date?(2001, 2, -1) # => true
See argument start.
See also
.valid_commercial?
.valid_jd?
.valid_civil?
.valid_ordinal?
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0