parsers/rfc_3339

Well tested

RFC3339 is a date serialization format.

There is a function to parse:

try parsed = rfc_3339.parse("00:00:00")
try parsed = rfc_3339.parse("1970-01-01")
try parsed = rfc_3339.parse("1970-01-01T00:00:00")
try parsed = rfc_3339.parse("1970-01-01T00:00:00Z")
try parsed = rfc_3339.parse("1970-01-01T00:00:00+00:00")

And a function to print:

rfc_3339.print(RFC3339LocalTime(LocalTime(0, 0, 0, None)))
|> io.debug()

The parser-combinator is public:

fn value() -> MyParser(Node) {
  string() |> p.map(VString)
  |> p.alt(fn() { rfc_3339.parser() |> p.map(VDateTime) })
}

Types

pub type Datetime {
  Datetime(date: LocalDate, time: LocalTime, timezone: Timezone)
}

Constructors

  • Datetime(date: LocalDate, time: LocalTime, timezone: Timezone)
pub type LocalDate {
  LocalDate(year: Int, month: Int, day: Int)
}

Constructors

  • LocalDate(year: Int, month: Int, day: Int)
pub type LocalDatetime {
  LocalDatetime(date: LocalDate, time: LocalTime)
}

Constructors

  • LocalDatetime(date: LocalDate, time: LocalTime)
pub type LocalTime {
  LocalTime(
    hour: Int,
    minutes: Int,
    seconds: Int,
    precision: Option(Int),
  )
}

Constructors

  • LocalTime(
      hour: Int,
      minutes: Int,
      seconds: Int,
      precision: Option(Int),
    )
pub type RFC3339 {
  RFC3339Datetime(Datetime)
  RFC3339LocalDatetime(LocalDatetime)
  RFC3339LocalDate(LocalDate)
  RFC3339LocalTime(LocalTime)
}

Constructors

  • RFC3339Datetime(Datetime)
  • RFC3339LocalDatetime(LocalDatetime)
  • RFC3339LocalDate(LocalDate)
  • RFC3339LocalTime(LocalTime)
pub type Timezone {
  TimezoneZulu
  TimezonePositive(hour: Int, minutes: Int)
  TimezoneNegative(hour: Int, minutes: Int)
}

Constructors

  • TimezoneZulu
  • TimezonePositive(hour: Int, minutes: Int)
  • TimezoneNegative(hour: Int, minutes: Int)

Functions

pub fn parse(it: String) -> Result(RFC3339, String)
pub fn parser() -> fn(Stream(String)) ->
  Result(ParseSuccess(String, RFC3339), ParseError(String))
pub fn print(it: RFC3339) -> String
Search Document