Add the option to treat minutes and hours flags as discounting from an 8 hr day

This commit is contained in:
Campbell Alden 2024-12-13 18:11:48 +09:00
parent 27b9345377
commit 7a6aa2489b
4 changed files with 11 additions and 3 deletions

2
Cargo.lock generated
View file

@ -384,7 +384,7 @@ dependencies = [
[[package]]
name = "time-track"
version = "2.0.1"
version = "2.1.0"
dependencies = [
"anyhow",
"chrono",

View file

@ -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

View file

@ -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,
}

View file

@ -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(())
}