duration_format

Package VersionHex Docs

Parse and format gleam/time/duration.Duration values in established string formats. Currently supports Go's time.ParseDuration grammar — the same format used by Prometheus, Kubernetes, HashiCorp tools (Terraform, Consul, Nomad), and InfluxDB.

gleam add duration_format
import duration_format/go
import gleam/io

pub fn main() -> Nil {
  let assert Ok(d) = go.parse("1h30m")
  io.println(go.to_string(d))
  // -> "1h30m0s"

  case go.parse("1d") {
    Ok(_) -> Nil
    Error(go.UnknownUnit(u)) -> io.println("unsupported unit: " <> u)
    Error(_) -> Nil
  }
}

Supported formats

Module Format
duration_format/go Go's time.ParseDuration grammar ("1h30m", "-2m3.4s", "500ms", …)

Each format module exposes its own parse, to_string, and Error type.

Other time libraries

duration_format only handles duration string formats. For broader time work, consider:

Development

gleam test                       # run tests
gleam format --check src test    # check formatting

Further documentation is at https://hexdocs.pm/duration_format.