fix: fill of elapsed time, remove local var

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2024-05-02 17:16:14 +02:00
parent c76f17a51e
commit 4ec9a36d07
Signed by: cafkafk
GPG key ID: 26C542FD97F965CE

View file

@ -12,20 +12,21 @@ fn main() -> io::Result<()> {
let time_only = NaiveTime::parse_from_str(&buffer, "%H:%M:%S").unwrap(); let time_only = NaiveTime::parse_from_str(&buffer, "%H:%M:%S").unwrap();
let local: DateTime<Local> = Local::now();
println!( println!(
"delta: \t\t{time_only} -> {}", "delta: \t\t{time_only} -> {}",
local.time().format("%H:%M:%S").to_string() Local::now().time().format("%H:%M:%S").to_string()
); );
let dt = NaiveTime::signed_duration_since(local.time(), time_only); let dt = NaiveTime::signed_duration_since(Local::now().time(), time_only);
let hours = (dt.num_seconds() / 60) / 60; let hours = (dt.num_seconds() / 60) / 60;
let minutes = (dt.num_seconds() / 60) % 60; let minutes = (dt.num_seconds() / 60) % 60;
let seconds = dt.num_seconds() % 60; let seconds = dt.num_seconds() % 60;
println!("elapsed: \t{}:{}:{}", &hours, &minutes, &seconds); println!(
"elapsed: \t{:0>2.}:{:0>2.}:{:0>2.}",
&hours, &minutes, &seconds
);
let total = format!("{}.{:.0}", &hours, 100. / 60. * minutes as f32) let total = format!("{}.{:.0}", &hours, 100. / 60. * minutes as f32)
.parse::<f64>() .parse::<f64>()