View Source PgInterop.Interval.ISO8601AlternativeParser (electric v0.9.5)

This module parses alternative ISO-8601 duration strings into Interval structs.

Summary

Functions

Parses an ISO-8601 formatted duration string into a Interval struct. The parse result is wrapped in a :ok/:error tuple.

Functions

@spec parse(String.t()) :: {:ok, PgInterop.Interval.t()} | {:error, term()}

Parses an ISO-8601 formatted duration string into a Interval struct. The parse result is wrapped in a :ok/:error tuple.

Examples

iex> parse("P0015-3-2T1:14:37.25")
{:ok, Interval.parse!("P15Y3M2DT1H14M37.25S")}

iex> parse("P0015-3-2")
{:ok, Interval.parse!("P15Y3M2D")}

iex> parse("PT3:12:25.001")
{:ok, Interval.parse!("PT3H12M25.001S")}

iex> parse("P0015T30:00")
{:ok, Interval.parse!("P15YT30H")}

iex> parse("")
{:error, "input string cannot be empty"}
iex> parse("W")
{:error, "expected P, got W"}
iex> parse("P0015TT30:00")
{:error, "unexpected duplicate T"}
iex> parse("P0015-3-2-1")
{:error, "unexpected 4th section in y-m-d part"}
iex> parse("P0015-3-y")
{:error, "invalid number `y`"}
iex> parse("P0015-3-1T30:00:10.y")
{:error, "invalid number `10.y`"}