time
This module contains functions for formatting durations of time to String
s (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)