From 7a6aa2489bc4ab8c0c01812421c01f3b2d646163 Mon Sep 17 00:00:00 2001 From: Campbell Alden Date: Fri, 13 Dec 2024 18:11:48 +0900 Subject: [PATCH] Add the option to treat minutes and hours flags as discounting from an 8 hr day --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/args.rs | 4 ++++ src/main.rs | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5aee76c..52be8ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -384,7 +384,7 @@ dependencies = [ [[package]] name = "time-track" -version = "2.0.1" +version = "2.1.0" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index f3dc1a8..ed1f106 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "time-track" -version = "2.0.1" +version = "2.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/args.rs b/src/args.rs index abee82c..e4a0c2d 100644 --- a/src/args.rs +++ b/src/args.rs @@ -11,4 +11,8 @@ pub struct Args { /// How many minutes you intend to work (sums with `hours`) #[arg(long, default_value_t = 0)] pub minutes: i64, + + /// If true, the the hours and minutes fields are treated as subtracting from 8 hours + #[arg(long, default_value_t = false)] + pub discount: bool, } diff --git a/src/main.rs b/src/main.rs index 945df04..6539549 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,7 +42,11 @@ fn main() -> Result<()> { total_minutes += (now - remaining).num_minutes(); } - let target_minutes = args.hours * 60 + args.minutes; + let target_minutes = if args.discount { + (8 * 60) - (args.hours * 60 + args.minutes) + } else { + args.hours * 60 + args.minutes + }; println!("{}", time::get_charaterized_time_remaining(total_minutes, target_minutes)); Ok(()) }