View Source DateTimeParser.Parser behaviour (DateTimeParser v1.2.0)
Interface for the DateTimeParser to use when parsing a string.
The flow is:
- Preflight the string to see if the parser is appropriate. Sometimes the parsing can happen at
this stage if it's a simple parser, for example it can be done in a single regex. Results of the
preflight, if needed, can be stored in the
struct.preflight
. - Parse the string. You have
context/0
to check if you should return a time, date, or datetime. Also make sure you're honoring the user's options supplied instruct.opts
You may create your own parser and use it with the DateTimeParser by creating a module that follows this behaviour.
Summary
Callbacks
Parse the string.
Determine if the string is appropriate to parse with this parser. If not, then other parsers will be attempted.
Types
@type context() :: :datetime | :date | :time | :best
Callbacks
@callback parse(t()) :: {:ok, DateTime.t() | NaiveDateTime.t() | Time.t() | Date.t()} | {:error, any()}
Parse the string.
Determine if the string is appropriate to parse with this parser. If not, then other parsers will be attempted.