Tokenizes an ISO 8601 (parts 1 and 2) or IXDTF string into a
list of tagged tokens that the internal parser then converts
into a Tempo.t/0 struct.
tokenize/1 returns a 2-tuple {tokens, extended_info} where
extended_info is either nil or a map of parsed
IXDTF
suffix information. See Tempo.Iso8601.Tokenizer.Extended for
the shape of the extended map.
Summary
Functions
Parses the given binary as date_only.
Parses the given binary as datetime_only.
Parses the given binary as duration_only.
Parses the given binary as interval_only.
Parses the given binary as iso8601.
Parses the given binary as time_only.
Tokenize an ISO 8601 or IXDTF string.
Tokenise a string that must match a single ISO 8601 profile.
Tokenise a string that must be an ISO 8601 duration.
Functions
@spec date_only(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses the given binary as date_only.
Returns {:ok, [token], rest, context, position, byte_offset} or
{:error, reason, rest, context, line, byte_offset} where position
describes the location of the date_only (start position) as {line, offset_to_start_of_line}.
To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line.
Options
:byte_offset- the byte offset for the whole binary, defaults to 0:line- the line and the byte offset into that line, defaults to{1, byte_offset}:context- the initial context value. It will be converted to a map
@spec datetime_only(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses the given binary as datetime_only.
Returns {:ok, [token], rest, context, position, byte_offset} or
{:error, reason, rest, context, line, byte_offset} where position
describes the location of the datetime_only (start position) as {line, offset_to_start_of_line}.
To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line.
Options
:byte_offset- the byte offset for the whole binary, defaults to 0:line- the line and the byte offset into that line, defaults to{1, byte_offset}:context- the initial context value. It will be converted to a map
@spec duration_only(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses the given binary as duration_only.
Returns {:ok, [token], rest, context, position, byte_offset} or
{:error, reason, rest, context, line, byte_offset} where position
describes the location of the duration_only (start position) as {line, offset_to_start_of_line}.
To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line.
Options
:byte_offset- the byte offset for the whole binary, defaults to 0:line- the line and the byte offset into that line, defaults to{1, byte_offset}:context- the initial context value. It will be converted to a map
@spec interval_only(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses the given binary as interval_only.
Returns {:ok, [token], rest, context, position, byte_offset} or
{:error, reason, rest, context, line, byte_offset} where position
describes the location of the interval_only (start position) as {line, offset_to_start_of_line}.
To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line.
Options
:byte_offset- the byte offset for the whole binary, defaults to 0:line- the line and the byte offset into that line, defaults to{1, byte_offset}:context- the initial context value. It will be converted to a map
@spec iso8601(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses the given binary as iso8601.
Returns {:ok, [token], rest, context, position, byte_offset} or
{:error, reason, rest, context, line, byte_offset} where position
describes the location of the iso8601 (start position) as {line, offset_to_start_of_line}.
To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line.
Options
:byte_offset- the byte offset for the whole binary, defaults to 0:line- the line and the byte offset into that line, defaults to{1, byte_offset}:context- the initial context value. It will be converted to a map
@spec time_only(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses the given binary as time_only.
Returns {:ok, [token], rest, context, position, byte_offset} or
{:error, reason, rest, context, line, byte_offset} where position
describes the location of the time_only (start position) as {line, offset_to_start_of_line}.
To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line.
Options
:byte_offset- the byte offset for the whole binary, defaults to 0:line- the line and the byte offset into that line, defaults to{1, byte_offset}:context- the initial context value. It will be converted to a map
Tokenize an ISO 8601 or IXDTF string.
Arguments
stringis any ISO 8601 formatted string, optionally with an IXDTF suffix (such as[Europe/Paris][u-ca=hebrew]).
Returns
{:ok, {tokens, extended_info}}wheretokensis the list of ISO 8601 tokens produced by the parser andextended_infois eithernil(when no IXDTF suffix was present) or a map with keys:calendar,:zone_id,:zone_offsetand:tags.{:error, reason}when the string cannot be parsed or a critical IXDTF suffix is unrecognised.
Tokenise a string that must match a single ISO 8601 profile.
Where tokenize/1 admits every shape the standard defines and
reports which one it found, this requires the whole input to be the
named shape — the caller has declared the profile its value belongs
to. A value that merely begins with that shape is rejected rather
than silently truncated.
Durations have their own entry point, tokenize_duration/1, because
a duration carries neither an EDTF qualification nor an IXDTF suffix
and so returns tokens alone rather than a {tokens, extended} pair.
Arguments
stringis the candidate ISO 8601 value.profileis one of:date,:datetime,:timeor:interval.
Returns
{:ok, {tokens, extended_info}}in the same shapetokenize/1returns.{:error, %Tempo.ParseError{}}when the string is not the named profile, or is that profile followed by anything else.
Tokenise a string that must be an ISO 8601 duration.
Unlike tokenize/1, which admits every shape the standard defines,
this recognises only a duration and requires the whole input to be
one — the caller has declared the profile its value belongs to.
Arguments
stringis the candidate duration.
Returns
{:ok, tokens}wheretokensis[duration: components], the same shapetokenize/1produces for a duration.{:error, %Tempo.ParseError{}}when the string is not a duration, or is a duration followed by anything else.