End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Date.parse
static VALUE
date_s_parse(int argc, VALUE *argv, VALUE klass)
{
VALUE str, comp, sg, opt;
rb_scan_args(argc, argv, "03:", &str, &comp, &sg, &opt);
if (!NIL_P(opt)) argc--;
switch (argc) {
case 0:
str = rb_str_new2("-4712-01-01");
case 1:
comp = Qtrue;
case 2:
sg = INT2FIX(DEFAULT_SG);
}
{
int argc2 = 2;
VALUE argv2[3];
argv2[0] = str;
argv2[1] = comp;
if (!NIL_P(opt)) argv2[argc2++] = opt;
VALUE hash = date_s__parse(argc2, argv2, klass);
return d_new_by_frags(klass, hash, sg);
}
}
Parses the given representation of date and time, and creates a date object.
This method **does not** function as a validator. If the input string does not match valid formats strictly, you may get a cryptic result. Should consider to use Date.strptime instead of this method as possible.
If the optional second argument is true and the detected year is in the range “00” to “99”, considers the year a 2-digit form and makes it full.
Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...> Date.parse('20010203') #=> #<Date: 2001-02-03 ...> Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
Raise an ArgumentError when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.