class ParseDate
- ParseDate
- Reference
- Object
Overview
This utility tries to brute force match a time/date against a hierarchy of possible formats in order to be able to broadly accept, and parse a wide range of date specifications.
It iterates through a list for formats, attempting to match against each date specification in turn, until either a match is found or the list is exhausted. The current set of formats is:
- Time::Format::YAML_DATE
- Time::Format::ISO_8601_DATE_TIME
- Time::Format::ISO_8601_DATE
- Time::Format::ISO_8601_TIME
- Time::Format::RFC_2822
- Time::Format::RFC_3339
- Time::Format::HTTP_DATE
- ParseDate::Format::UsMil
Defined in:
format/usmil.crparse_date.cr
Constant Summary
-
DEFAULT_FORMATS =
[Time::Format::YAML_DATE, Time::Format::ISO_8601_DATE_TIME, Time::Format::ISO_8601_DATE, Time::Format::ISO_8601_TIME, Time::Format::RFC_2822, Time::Format::RFC_3339, Time::Format::HTTP_DATE, ParseDate::Format::UsMil]
-
VERSION =
"0.1.1"
Class Method Summary
-
.parse(string : String | Nil, fallback : Bool = true, formats = DEFAULT_FORMATS) : Time | Nil
Parse a string into a Time.
Class Method Detail
Parse a string into a Time.
The string to parse is a mandatory argument. If a nil is received, the method will return nil.
If fallback
is set to true (the default), then if the date can not
be parsed, it will attempt to convert slashes to dashes before trying
again.
The formats
parameter can be used to overide the default list of
formats to attempt to match. If omitted, the default set specified
above is used.