anmolitor / elm-protoc-utils / Protobuf.Utils.Duration

Conversions between the Protobuf Well-Known Type "Duration" and Milliseconds as a Int to be compatable with Elm's Time.Posix.

millisToDuration : Basics.Float -> Duration

Convert a number of milliseconds to a Duration. Note that this only guarantees keeping precision in the millisecond range - micro/nanoseconds can be lost due to floating point arithmetic.

durationToMillis : Duration -> Basics.Float

Convert a Duration to a number of milliseconds. Note that this only guarantees keeping precision in the millisecond range - micro/nanoseconds can be lost due to floating point arithmetic.

durationJsonEncoder : Duration -> Json.Encode.Value

Custom Json Encoder for Duration, which formats a duration as a string. For example, 123 seconds and 450 milliseconds is encoded as "123.45s".

durationJsonDecoder : Json.Decode.Decoder Duration

Custom Json Decoder for Duration, which accepts a duration as a string matching the above format (number of seconds with a "s" suffix).