summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucien Fiorini <lucienfiorini@protonmail.com>2021-12-20 22:58:25 +0100
committerGitHub <noreply@github.com>2021-12-20 15:58:25 -0600
commita8579d6f2feb3e4929de2b4b93f244479d1d6752 (patch)
tree1293aa36475779d35b23dc98b80e94863bd8fcb5
parentd0a6ce7faa65abe86b1f3d2021c5c21939f87b73 (diff)
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"
-rw-r--r--src/utils.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index deac5b2b3..6dc27a874 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -454,6 +454,11 @@ fn internal_exec_cmd<T: AsRef<OsStr> + Debug, U: AsRef<OsStr> + 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);
@@ -506,6 +511,10 @@ 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")
}