Timex.Parsers.DateFormat.Parser behaviour
This is the base plugin behavior for all Timex date/time string parsers.
Summary↑
parse!(date_string, format_string, parser \\ Timex.Parsers.DateFormat.DefaultParser) | |
parse(date_string, format_string) | Parses a date/time string using the default parser |
parse(date_string, format_string, parser) | Parses a date/time string using the provided parser. Must implement the
|
update_date(date, token, value) | |
valid_length?(error, token, len) | Given a string value (as a charlist), a token name, and a length specification, return a boolean indicating the validity of the string length of the provided value |
valid_value?(str, token, validator) | Validates the value against a validator, the validator can be false, an atom representing a Date.* function to be called, a function taking a single string parameter, or a regex |
within_bounds?(str, token, min, max) | Validate that a numeric value is within the valid range, if applicable. If not return an appropriate error |
Functions
Specs:
- parse(binary, binary) :: {:ok, %Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term}} | {:error, term}
Parses a date/time string using the default parser.
Examples
iex> Elixir.Timex.Parsers.DateFormat.Parser.parse(“2014-07-29T00:20:41.196Z”, “{ISOz}”) %Date{year: 2014, month: 7, day: 29, hour: 0, minute: 20, second: 41, ms: 196, tz: %Timezone{name: “CST”}}
Specs:
- parse(binary, binary, Timex.Parsers.DateFormat.Parser) :: {:ok, %Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term}} | {:error, term}
Parses a date/time string using the provided parser. Must implement the
Timex.Parsers.Parser
behaviour.
Examples
iex> Elixir.Timex.Parsers.DateFormat.Parser.parse(“2014-07-29T00:30:41.196Z”, “{ISOz}”, Timex.Parsers.DefaultParser) %Date{year: 2014, month: 7, day: 29, hour: 0, minute: 20, second: 41, ms: 196, tz: %Timezone{name: “CST”}}
Specs:
- parse!(String.t, String.t, Timex.Parsers.DateFormat.Parser | nil) :: %Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term} | no_return
Given a string value (as a charlist), a token name, and a length specification, return a boolean indicating the validity of the string length of the provided value.
Example
valid_length?(‘Mar’, :mshort, 3..4) #=> true
Validates the value against a validator, the validator can be false, an atom representing a Date.* function to be called, a function taking a single string parameter, or a regex.
Example
valid_value?(‘+0200’, :zname, ~r/^[-+]{4}$/) #=> true
Validate that a numeric value is within the valid range, if applicable. If not return an appropriate error.
Example
within_bounds?(“61”, :min, 0, 59) #=> false
Callbacks
Specs:
- apply_directives(tokens :: [{token :: atom, value :: term}]) :: {:ok, %Timex.DateTime{calendar: term, day: term, hour: term, minute: term, month: term, ms: term, second: term, timezone: term, year: term}} | {:error, term}
Specs:
- parse_directive(date :: binary, directive :: %Timex.Parsers.DateFormat.Directive{format: term, len: term, match: term, max: term, min: term, optional: term, pad: term, pad_type: term, raw: term, token: term, type: term, validate: term}) :: {token :: atom, {value :: term, date_rest :: binary} | {:error, term}}
Specs:
- tokenize(format_string :: binary) :: [%Timex.Parsers.DateFormat.Directive{format: term, len: term, match: term, max: term, min: term, optional: term, pad: term, pad_type: term, raw: term, token: term, type: term, validate: term}] | {:error, term}