Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Date._parse

Date._parse(string[, comp=true], limit: 128) → hash

Parses the given representation of date and time, and returns a hash of parsed elements.

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 or DateTime._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.

Example
Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}

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.

See also .ordinal .parse .nth_kday ._rfc2822 also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1