pub fn format_duration(duration: i64) -> String {
    let (sign, duration) = if duration >= 0 {
        (1, duration)
    } else {
        (-1, -duration)
    };
    let (micros, nanos): (i64, i64) = (duration / 1000, duration % 1000);
    let (millis, micros): (i64, i64) = (micros / 1000, micros % 1000);
    let (secs, millis): (i64, i64) = (millis / 1000, millis % 1000);
    let (mins, secs): (i64, i64) = (secs / 60, secs % 60);
    let (hours, mins): (i64, i64) = (mins / 60, mins % 60);
    let (days, hours): (i64, i64) = (hours / 24, hours % 24);

    let mut output_prep = vec![];

    if days != 0 {
        output_prep.push(format!("{}day", days));
    }

    if hours != 0 {
        output_prep.push(format!("{}hr", hours));
    }

    if mins != 0 {
        output_prep.push(format!("{}min", mins));
    }
    // output 0sec for zero duration
    if duration == 0 || secs != 0 {
        output_prep.push(format!("{}sec", secs));
    }

    if millis != 0 {
        output_prep.push(format!("{}ms", millis));
    }

    if micros != 0 {
        output_prep.push(format!("{}us", micros));
    }

    if nanos != 0 {
        output_prep.push(format!("{}ns", nanos));
    }

    format!(
        "{}{}",
        if sign == -1 { "-" } else { "" },
        output_prep.join(" ")
    )
}
/// Format a duration in nanoseconds into a string
Format a duration in nanoseconds into a string
Format a duration in nanoseconds into a string
pub fn format_duration(duration: i64) -> String {
    let (sign, duration) = if duration >= 0 {
        (1, duration)
    } else {
        (-1, -duration)
    };
    let (micros, nanos): (i64, i64) = (duration / 1000, duration % 1000);
    let (millis, micros): (i64, i64) = (micros / 1000, micros % 1000);
    let (secs, millis): (i64, i64) = (millis / 1000, millis % 1000);
    let (mins, secs): (i64, i64) = (secs / 60, secs % 60);
    let (hours, mins): (i64, i64) = (mins / 60, mins % 60);
    let (days, hours): (i64, i64) = (hours / 24, hours % 24);
    let mut output_prep = vec![];
    if days != 0 {
        output_prep.push(format!("{}day", days));
    }
    if hours != 0 {
        output_prep.push(format!("{}hr", hours));
    }
    if mins != 0 {
        output_prep.push(format!("{}min", mins));
    }
    // output 0sec for zero duration
    if duration == 0 || secs != 0 {
        output_prep.push(format!("{}sec", secs));
    }
    if millis != 0 {
        output_prep.push(format!("{}ms", millis));
    }
    if micros != 0 {
        output_prep.push(format!("{}us", micros));
    }
    if nanos != 0 {
        output_prep.push(format!("{}ns", nanos));
    }
    format!(
        "{}{}",
        if sign == -1 { "-" } else { "" },
        output_prep.join(" ")
    )
}
pub fn format_duration ( duration : i64 ) -> String { let ( sign , duration ) = if duration >= 0 { ( 1 , duration ) } else { ( - 1 , - duration ) } ; let ( micros , nanos ) : ( i64 , i64 ) = ( duration / 1000 , duration % 1000 ) ; let ( millis , micros ) : ( i64 , i64 ) = ( micros / 1000 , micros % 1000 ) ; let ( secs , millis ) : ( i64 , i64 ) = ( millis / 1000 , millis % 1000 ) ; let ( mins , secs ) : ( i64 , i64 ) = ( secs / 60 , secs % 60 ) ; let ( hours , mins ) : ( i64 , i64 ) = ( mins / 60 , mins % 60 ) ; let ( days , hours ) : ( i64 , i64 ) = ( hours / 24 , hours % 24 ) ; let mut output_prep = vec ! [ ] ; if days != 0 { output_prep . push ( format ! ( " " days ) ) ; } if hours != 0 { output_prep . push ( format ! ( " " hours ) ) ; } if mins != 0 { output_prep . push ( format ! ( " " mins ) ) ; } // output 0sec for zero duration if duration == 0 || secs != 0 { output_prep . push ( format ! ( " " secs ) ) ; } if millis != 0 { output_prep . push ( format ! ( " " millis ) ) ; } if micros != 0 { output_prep . push ( format ! ( " " micros ) ) ; } if nanos != 0 { output_prep . push ( format ! ( " " nanos ) ) ; } format ! ( " " if sign 1 { " " } else { " " } output_prep join ( " " ) ) }
Format a duration in nanoseconds into a string
Format a duration in nanoseconds into a string
duration
i64