From a8579d6f2feb3e4929de2b4b93f244479d1d6752 Mon Sep 17 00:00:00 2001 From: Lucien Fiorini Date: Mon, 20 Dec 2021 22:58:25 +0100 Subject: [PATCH] fix: Display durations of 0ms (#3121) Previous code would render all components as empty, resulting in an empty string even if min_time was 0. This adds a special case which forces prompt to render "0ms" --- src/utils.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index deac5b2b..6dc27a87 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -454,6 +454,11 @@ fn internal_exec_cmd + Debug, U: AsRef + Debug>( // Render the time into a nice human-readable string pub fn render_time(raw_millis: u128, show_millis: bool) -> String { + // Make sure it renders something if the time equals zero instead of an empty string + if raw_millis == 0 { + return "0ms".into(); + } + // Calculate a simple breakdown into days/hours/minutes/seconds/milliseconds let (millis, raw_seconds) = (raw_millis % 1000, raw_millis / 1000); let (seconds, raw_minutes) = (raw_seconds % 60, raw_seconds / 60); @@ -505,6 +510,10 @@ pub fn encode_to_hex(slice: &[u8]) -> String { mod tests { use super::*; + #[test] + fn test_0ms() { + assert_eq!(render_time(0_u128, true), "0ms") + } #[test] fn test_500ms() { assert_eq!(render_time(500_u128, true), "500ms")