Bug Fix: Count time from now if the end time is before now

This commit is contained in:
Campbell Alden 2024-12-27 09:36:49 +09:00
parent 2b55df907b
commit 51a200d1a3
3 changed files with 15 additions and 12 deletions

2
Cargo.lock generated
View file

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

View file

@ -1,6 +1,6 @@
[package]
name = "time-track"
version = "2.1.3"
version = "2.1.4"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -70,9 +70,10 @@ pub fn get_charaterized_time_remaining(
} else {
let diff = target_minutes - total_minutes;
let (hours, minutes) = to_hrs_minutes(diff);
let now = Local::now();
return if ended_at > now {
let end_at = (ended_at + Duration::minutes(diff)).time();
let end_str = end_at.format("%-I:%M %p");
return if ended_at > Local::now() {
format!(
"You have {} remaining (end at {} starting from {})",
show_time(hours, minutes),
@ -80,6 +81,8 @@ pub fn get_charaterized_time_remaining(
ended_at.format("%-I:%M %p"),
)
} else {
let end_at = (now + Duration::minutes(diff)).time();
let end_str = end_at.format("%-I:%M %p");
format!("You have {} remaining (end at {} starting now)", show_time(hours, minutes), end_str)
}
}