time

This module contains functions for formatting durations of time to Strings (e.g. "100.0ms", "1.5s").

Usage generally looks like this:

time.Millisecond(2000.0) |> time.humanise |> time.to_string // "2.0s"

// or, if you don't want to change the unit
time.Millisecond(2000.0) |> time.to_string // "2000.0ms"

Types

The main type for holding time information.

Use its constructors directly to specify a unit for the value you want to format.

pub type Time {
  Microseconds(Float)
  Milliseconds(Float)
  Seconds(Float)
  Minutes(Float)
  Hours(Float)
  Days(Float)
  Weeks(Float)
}

Constructors

  • Microseconds(Float)
  • Milliseconds(Float)
  • Seconds(Float)
  • Minutes(Float)
  • Hours(Float)
  • Days(Float)
  • Weeks(Float)

Functions

pub fn humanise(this time: Time) -> Time

Convert a value to a more optimal unit, if possible.

Example:

time.Seconds(120.0) |> time.humanise // time.Minutes(2.0)
pub fn to_string(this time: Time) -> String

Format a value as a String, rounded to at most 2 decimal places, followed by a unit suffix.

Example:

time.Seconds(30.125) |> time.to_string // "30.13s"
Search Document