[][src]Function ms_converter::get_duration_by_postfix

pub fn get_duration_by_postfix<'a, P>(
    milliseconds: i64,
    postfix: P
) -> Result<String, Error> where
    P: Into<Cow<'a, str>>, 

Getting human-like time from milliseconds. get_duration_by_postfix function gets a milliseconds count and str slice or String as postfix and returns a string with your time.

Usage

use crate::ms_converter::{get_duration_by_postfix, DAY};

let value = get_duration_by_postfix(1 * DAY as i64, "day").unwrap();
assert_eq!(value, "1day")

You can add the space to start of you prefix to get space between date and postfix on return.

use crate::ms_converter::{get_duration_by_postfix, DAY};

let value = get_duration_by_postfix(DAY as i64, " day").unwrap();
assert_eq!(value, "1 day")

also you can a pass negative values

use crate::ms_converter::{get_duration_by_postfix, DAY};

let value = get_duration_by_postfix(-DAY as i64, " day").unwrap();
assert_eq!(value, "-1 day")

Supported postfixes

  • Years: years, year, yrs, yr, y
  • Weeks: weeks, week, w
  • Days: days, day, d
  • Hours: hours, hour, hrs, hr, h
  • Minutes: minutes, minute, mins, min, m
  • Seconds: seconds, second, secs, sec, s
  • Milliseconds: milliseconds, millisecond, msecs, msec, ms and empty postfix