From df02ab447b4d6e94901508961aee6d631742cf67 Mon Sep 17 00:00:00 2001 From: Campbell Alden Date: Tue, 16 Jan 2024 17:39:25 +0900 Subject: [PATCH] Handle hours and minutes pluralization --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ccacc4..810335e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,7 +360,7 @@ dependencies = [ [[package]] name = "time-track" -version = "0.3.2" +version = "0.3.3" dependencies = [ "anyhow", "atty", diff --git a/Cargo.toml b/Cargo.toml index 880c8e4..231bb42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "time-track" -version = "0.3.2" +version = "0.3.3" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 2a9e7ed..70cd406 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,8 +124,16 @@ fn main() { let total_minutes: i64 = durations.iter().map(|d| { d.num_minutes() }).sum(); let minutes = total_minutes % 60; let hours = total_minutes / 60; + let pluralized_hours = match hours { + 1 => "hour", + _ => "hours", + }; + let pluralized_minutes = match minutes { + 1 => "minute", + _ => "minutes", + }; - println!("You have been working for {hours} hour(s) and {minutes} minute(s)"); + println!("You have been working for {hours} {pluralized_hours} and {minutes} {pluralized_minutes}"); }, Err(err) => eprintln!("{}\nExiting...", err), }