From 353edab3dd40d34ae34c3d773b55a642c64b0ed3 Mon Sep 17 00:00:00 2001 From: HitBlast Date: Thu, 26 Dec 2024 11:53:42 +0600 Subject: [PATCH] v0.1.9 --- CHANGELOG.md | 11 +++ Cargo.lock | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +- src/lib.rs | 20 +++++- src/main.rs | 38 ++++++++-- 5 files changed, 257 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9c0290..2f6dc21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v0.1.9] - 2024.12.2 + +### Added + +- Calculation of the estimated time remaining in current day after trimming (by @hitblast) + +### Changed + +- Support for calculating even at 1x multiplier (correlate with "Added" section) (by @hitblast) +- "Better?" text output formatting (by @hitblast) + ## [v0.1.8] - 2024.12.26 ### Added diff --git a/Cargo.lock b/Cargo.lock index 51c4d40..3fb2b74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.18" @@ -51,6 +66,47 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "cc" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + [[package]] name = "clap" version = "4.5.23" @@ -107,24 +163,90 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "js-sys" +version = "0.3.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "libc" +version = "0.2.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + [[package]] name = "proc-macro2" version = "1.0.92" @@ -143,6 +265,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "strsim" version = "0.11.1" @@ -162,8 +290,9 @@ dependencies = [ [[package]] name = "trimsec" -version = "0.1.8" +version = "0.1.9" dependencies = [ + "chrono", "clap", "colored", ] @@ -180,6 +309,69 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "wasm-bindgen" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.59.0" diff --git a/Cargo.toml b/Cargo.toml index bfb2f1f..c16d1fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "trimsec" description = "Calculate saved time on using media speed multipliers, with speed." authors = ["HitBlast "] -version = "0.1.8" +version = "0.1.9" edition = "2021" repository = "https://github.com/hitblast/trimsec" homepage = "https://github.com/hitblast/trimsec" @@ -11,5 +11,6 @@ readme = "README.md" exclude = ["assets/*"] [dependencies] +chrono = "0.4.39" clap = { version = "4.5.23", features = ["derive"] } colored = "2.2.0" diff --git a/src/lib.rs b/src/lib.rs index 61f0aeb..4f3b684 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,14 @@ use std::fmt::Display; +use chrono::{Datelike, TimeZone}; + /// The primary run function. pub fn run(config: Config) -> Result<(f64, f64, i64), TrimsecError> { Ok(trim(config)) } /// Calculate how much time has been saved by using a multiplier. +/// Returns a tuple with the new duration, saved time, and the number of splits. pub fn trim(config: Config) -> (f64, f64, i64) { let old_duration = config.duration; let multiplier = config.multiplier; @@ -89,7 +92,7 @@ fn parse_multiplier(multiplier_user: &str) -> Result { .parse() .map_err(|_| TrimsecError::InvalidMultiplierFormat)?; - if multiplier_value <= 1.0 || multiplier_value >= 100.0 { + if multiplier_value < 1.0 || multiplier_value >= 100.0 { Err(TrimsecError::MultiplierOutOfRange) } else { Ok(multiplier_value) @@ -164,6 +167,21 @@ fn parse_duration(duration: &str) -> Result<(f64, i64), TrimsecError> { Ok((total_seconds, splits)) } +/// Function to check the time efficiency for the current day. +pub fn calculate_remaining(trimmed_dur: f64) -> f64 { + let now = chrono::Local::now(); + let end_of_day = chrono::Local + .with_ymd_and_hms(now.year(), now.month(), now.day(), 23, 59, 59) + .unwrap(); + let duration = end_of_day.signed_duration_since(now).num_seconds() as f64; + + if duration > trimmed_dur { + duration - trimmed_dur + } else { + 0.0 + } +} + /// Unit tests. #[cfg(test)] mod tests { diff --git a/src/main.rs b/src/main.rs index 140bfa7..8e2f684 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,7 +45,7 @@ fn main() { match result { Ok((new_duration, time_saved, splits)) => { // duration - if !args.time_saved_only { + if !args.time_saved_only && time_saved > 0.0 { let parsed = if args.seconds { format!("{:.2}s", new_duration) } else { @@ -53,7 +53,7 @@ fn main() { }; let message = format!( - "\nNew duration: {}{}", + " New duration: {}{} ", if args.emoji { "⏳ " } else { r#""# }, if splits > 1 { format!("{} ({} splits)", parsed, splits) @@ -65,17 +65,43 @@ fn main() { println!("{}", message); } + // remaining time in current day + if !args.duration_only && !args.time_saved_only { + let remaining = trimsec::calculate_remaining(new_duration); + println!( + " Time leftover in day: {}{} ", + if args.emoji { + if remaining > 0.0 { + "🟢 " + } else { + "🔴 " + } + } else { + r#""# + }, + if args.seconds { + format!("{:.2}s", remaining) + } else { + trimsec::parse_time(remaining) + } + ); + } + // saved time - if !args.duration_only { + if !args.duration_only && time_saved > 0.0 { let parsed = if args.seconds { format!("{:.2}s", time_saved) } else { trimsec::parse_time(time_saved) }; println!( - "Saved {}{}!\n", - if args.emoji { "⏰ " } else { r#""# }, - parsed.green() + "{}", + format!( + " Saved {}{}! ", + if args.emoji { "⏰ " } else { r#""# }, + parsed + ) + .green() ); } }