From e5264b449f5181add21feda1eeedcce6c7fb241c Mon Sep 17 00:00:00 2001 From: anesthetice <118751106+anesthetice@users.noreply.github.com> Date: Sat, 15 Jun 2024 00:41:34 +0200 Subject: [PATCH] night owl config --- Cargo.toml | 2 +- src/cli.rs | 4 ++-- src/config.rs | 7 ++++++- src/main.rs | 11 +++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 747df25..3769a38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "syracuse" -version = "2.1.2" +version = "2.1.3" edition = "2021" [dependencies] diff --git a/src/cli.rs b/src/cli.rs index 2c90a6e..7b1e2ad 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -368,7 +368,7 @@ pub fn process_update_subcommand(arg_matches: &ArgMatches, entries: &Entries, to entry.save()?; println!("{} : {} {} {}", &date, &tmp, "――>".green(), ns_to_pretty_string(entry.get_block_duration(&date))) } - else if ["sub", "rem", "remove", "minus", "decr", "decrease"].iter().any(|s| *s == operation) { + else if ["sub", "rm", "rem", "remove", "minus", "decr", "decrease"].iter().any(|s| *s == operation) { let tmp = ns_to_pretty_string(entry.get_block_duration(&date)); entry.decrease_bloc_duration(&date, total_diff); entry.save()?; @@ -449,7 +449,7 @@ pub fn process_backup_subcommand(arg_matches: &ArgMatches, entries: &Entries, to info!("directory already exists, this is not feasible"); } } - println!("backing up to: '{:?}'", &path); + println!("backing up to: '{}'", &path.display()); entries.backup(path); Ok(PO::Terminate) diff --git a/src/config.rs b/src/config.rs index 5c32621..8d0c2bf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,10 @@ pub struct Config { // realistically this could also just be an argument option in the CLI, but I personally want // it to be always on, so there we go.. pub stopwatch_explicit: bool, + // by how many hours should the day be extended after midnight + // e.g. 2 -> timers started until 2 a.m. on a given day will count towards the previous day + // useful for night owls + pub night_owl_hour_extension: u8, // threshold for results to be considered pub search_threshold: f64, @@ -72,6 +76,7 @@ impl Default for Config { local_offset: [0, 0, 0], backup_path: "".to_string(), stopwatch_explicit: false, + night_owl_hour_extension: 0, search_threshold: 0.0, sw_nw_ratio: 0.5, match_score: 2, @@ -104,7 +109,7 @@ impl Default for Config { (250, 234, 93), // mountain lake green (117, 185, 150), - // ceulean + // cerulean (0, 143, 190), ] } diff --git a/src/main.rs b/src/main.rs index c180c03..9883728 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use directories::ProjectDirs; use cli::{ process_add_subcommand, process_backup_subcommand, process_graph_subcommand, process_list_subcommand, process_prune_subcommand, process_remove_subcommand, process_start_subcommand, process_today_subcommand, process_update_subcommand, ProcessOutput as PO }; -use data::internal::Entries; +use data::{internal::Entries, syrtime::SyrDate}; fn main() -> anyhow::Result<()> { // start of initialization let dirs = ProjectDirs::from("", "", "syracuse").context("failed to get project directories")?; @@ -39,8 +39,15 @@ fn main() -> anyhow::Result<()> { }, } }; - let date = datetime.date().into(); let time = datetime.time(); + let date: SyrDate = { + if time.hour() < config::Config::get().night_owl_hour_extension { + datetime.date().previous_day().unwrap_or(datetime.date()).into() + } + else { + datetime.date().into() + } + }; let entries = Entries::load()?; // end of initialization