figbus/elm-urbit-api/4.0.1

Urbit.Encoding.DateAbsolute

Encoding/Decoding module for urbit @da representations of absolute dates, in accordance with https://urbit.org/docs/hoon/reference/auras.

Note: All dates in this format are in the UTC time zone.

Date Record

type alias DateRecord =
{ year : Int
, month : Int
, day : Int
, hour : Int
, minute : Int
, second : Int
, millis : Int
}

An absolute date stored as a record.

fromDateRecord : DateRecord -> String

Convert a DateRecord to a @da encoded string.

fromDateRecord
    { year = 2021
    , month = 8
    , day = 3
    , hour = 6
    , minute = 39
    , second = 55
    , millis = 356
    }
--> "~2021.8.3..6.39.55..05b2"
toDateRecord : String -> Result (List DeadEnd) DateRecord

Convert a @da encoded string to a DateRecord, failing on improperly formatted strings.

toDateRecord "~2021.8.3..6.39.55..05b2"
--> Ok
-->    { year = 2021
-->    , month = 8
-->    , day = 3
-->    , hour = 6
-->    , minute = 39
-->    , second = 55
-->    , millis = 356
-->    }

Posix Time

fromPosix : Posix -> String

Convert a posix time to a @da encoded string.

import Time


Time.millisToPosix 1627948800000 |> fromPosix
--> "~2021.8.3"
toPosix : String -> Result (List DeadEnd) Posix

Try to convert a @da encoded string to a posix time, failing on improperly formatted strings.

import Time


toPosix "~2021.8.3..8.25.00"
--> Ok (Time.millisToPosix 1627979100000)

Parsing

parseDateRecord : Parser DateRecord

Parses a @da encoded string into a DateRecord.

parsePosix : Parser Posix

Parses a @da encoded string into a posix time.