Skip to content

Commit

Permalink
v0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
hitblast committed Dec 26, 2024
1 parent 018d70b commit 353edab
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
194 changes: 193 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "trimsec"
description = "Calculate saved time on using media speed multipliers, with speed."
authors = ["HitBlast <[email protected]>"]
version = "0.1.8"
version = "0.1.9"
edition = "2021"
repository = "https://github.com/hitblast/trimsec"
homepage = "https://github.com/hitblast/trimsec"
Expand All @@ -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"
20 changes: 19 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -89,7 +92,7 @@ fn parse_multiplier(multiplier_user: &str) -> Result<f64, TrimsecError> {
.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)
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 353edab

Please sign in to comment.