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]]
|
||||
name = "time-track"
|
||||
version = "2.1.3"
|
||||
version = "2.1.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
23
src/time.rs
23
src/time.rs
|
|
@ -70,17 +70,20 @@ pub fn get_charaterized_time_remaining(
|
|||
} else {
|
||||
let diff = target_minutes - total_minutes;
|
||||
let (hours, minutes) = to_hrs_minutes(diff);
|
||||
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),
|
||||
end_str,
|
||||
ended_at.format("%-I:%M %p"),
|
||||
)
|
||||
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");
|
||||
format!(
|
||||
"You have {} remaining (end at {} starting from {})",
|
||||
show_time(hours, minutes),
|
||||
end_str,
|
||||
ended_at.format("%-I:%M %p"),
|
||||
)
|
||||
} else {
|
||||
format!("You have {} remaining (end at {} starting now)", show_time(hours, minutes), end_str)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue