humanise

This module contains a bunch of shortcuts to the time, bytes and ‘bytes1024’ modules for directly “humanising” and formatting a number (Float or Int) to a String.

For more control (e.g. work with time.Time or bytes.Bytes directly, use the given unit instead of the most optimal one), look at the time, bytes or bytes1024 modules.

Functions

pub fn bytes_float(from n: Float) -> String

Format n bytes as a Float, converting to a more optimal unit if possible.

pub fn bytes_int(from n: Int) -> String

Format n bytes as an Int, converting to a more optimal unit if possible.

pub fn date(
  from date: #(Date, TimeOfDay),
  now current: Date,
) -> String

Format a Date, TimeOfDay pair, automatically omitting redundant information (omit year if it matches the current year, omit month and day if it also matches the current day)

The given date will be compared against the provided “current” date to determine what information to omit.

This function does not currently support internationalization, and simply returns a string in the following largest-to-smallest format:

<maybe year> <maybe <month> <day>> <hours>:<minutes>:<seconds>

Note that hours are in 24 hour format, not 12 hours with AM/PM.

pub fn date_relative(
  from date: Timestamp,
  now current: Timestamp,
) -> String

Format a Timestamp relative to the provided current Timestamp.

This function finds the difference between the current time and the given time, and returns a string describing the difference. (e.g. “in 2.0s”, “3.5d ago”)

pub fn days_float(from n: Float) -> String

Format n days as a Float, converting to a more optimal unit if possible.

pub fn days_int(from n: Int) -> String

Format n days as an Int, converting to a more optimal unit if possible.

pub fn duration(from duration: Duration) -> String

Format a Duration, using the most optimal unit.

pub fn gibibytes_float(from n: Float) -> String

Format n gibibytes as a Float, converting to a more optimal unit if possible.

pub fn gibibytes_int(from n: Int) -> String

Format n gibibytes as an Int, converting to a more optimal unit if possible.

pub fn gigabytes_float(from n: Float) -> String

Format n gigabytes as a Float, converting to a more optimal unit if possible.

pub fn gigabytes_int(from n: Int) -> String

Format n gigabytes as an Int, converting to a more optimal unit if possible.

pub fn hours_float(from n: Float) -> String

Format n hours as a Float, converting to a more optimal unit if possible.

pub fn hours_int(from n: Int) -> String

Format n hours as an Int, converting to a more optimal unit if possible.

pub fn kibibytes_float(from n: Float) -> String

Format n kibibytes as a Float, converting to a more optimal unit if possible.

pub fn kibibytes_int(from n: Int) -> String

Format n kibibytes as an Int, converting to a more optimal unit if possible.

pub fn kilobytes_float(from n: Float) -> String

Format n kilobytes as a Float, converting to a more optimal unit if possible.

pub fn kilobytes_int(from n: Int) -> String

Format n kilobytes as an Int, converting to a more optimal unit if possible.

pub fn mebibytes_float(from n: Float) -> String

Format n mebibytes as a Float, converting to a more optimal unit if possible.

pub fn mebibytes_int(from n: Int) -> String

Format n mebibytes as an Int, converting to a more optimal unit if possible.

pub fn megabytes_float(from n: Float) -> String

Format n megabytes as a Float, converting to a more optimal unit if possible.

pub fn megabytes_int(from n: Int) -> String

Format n megabytes as an Int, converting to a more optimal unit if possible.

pub fn microseconds_float(from n: Float) -> String

Format n microseconds as a Float, converting to a more optimal unit if possible.

pub fn microseconds_int(from n: Int) -> String

Format n microseconds as an Int, converting to a more optimal unit if possible.

pub fn milliseconds_float(from n: Float) -> String

Format n milliseconds as a Float, converting to a more optimal unit if possible.

pub fn milliseconds_int(from n: Int) -> String

Format n milliseconds as an Int, converting to a more optimal unit if possible.

pub fn nanoseconds_float(from n: Float) -> String

Format n nanoseconds as a Float, converting to a more optimal unit if possible.

pub fn nanoseconds_int(from n: Int) -> String

Format n nanoseconds as a Float, converting to a more optimal unit if possible.

pub fn seconds_float(from n: Float) -> String

Format n seconds as a Float, converting to a more optimal unit if possible.

pub fn seconds_int(from n: Int) -> String

Format n seconds as an Int, converting to a more optimal unit if possible.

pub fn tebibytes_float(from n: Float) -> String

Format n tebibytes as a Float, converting to a more optimal unit if possible.

pub fn tebibytes_int(from n: Int) -> String

Format n tebibytes as an Int, converting to a more optimal unit if possible.

pub fn terabytes_float(from n: Float) -> String

Format n terabytes as a Float, converting to a more optimal unit if possible.

pub fn terabytes_int(from n: Int) -> String

Format n terabytes as an Int, converting to a more optimal unit if possible.

pub fn weeks_float(from n: Float) -> String

Format n weeks as a Float, converting to a more optimal unit if possible.

pub fn weeks_int(from n: Int) -> String

Format n weeks as an Int, converting to a more optimal unit if possible.

Search Document