Bug Fix: Count time from now if the end time is before now
This commit is contained in:
parent
2b55df907b
commit
51a200d1a3
3 changed files with 15 additions and 12 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -384,7 +384,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time-track"
|
name = "time-track"
|
||||||
version = "2.1.3"
|
version = "2.1.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "time-track"
|
name = "time-track"
|
||||||
version = "2.1.3"
|
version = "2.1.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,10 @@ pub fn get_charaterized_time_remaining(
|
||||||
} else {
|
} else {
|
||||||
let diff = target_minutes - total_minutes;
|
let diff = target_minutes - total_minutes;
|
||||||
let (hours, minutes) = to_hrs_minutes(diff);
|
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_at = (ended_at + Duration::minutes(diff)).time();
|
||||||
let end_str = end_at.format("%-I:%M %p");
|
let end_str = end_at.format("%-I:%M %p");
|
||||||
return if ended_at > Local::now() {
|
|
||||||
format!(
|
format!(
|
||||||
"You have {} remaining (end at {} starting from {})",
|
"You have {} remaining (end at {} starting from {})",
|
||||||
show_time(hours, minutes),
|
show_time(hours, minutes),
|
||||||
|
|
@ -80,6 +81,8 @@ pub fn get_charaterized_time_remaining(
|
||||||
ended_at.format("%-I:%M %p"),
|
ended_at.format("%-I:%M %p"),
|
||||||
)
|
)
|
||||||
} else {
|
} 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)
|
format!("You have {} remaining (end at {} starting now)", show_time(hours, minutes), end_str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue