From 002ad36068a134db154c3e0930946c19187efff4 Mon Sep 17 00:00:00 2001 From: Trevor Merritt Date: Tue, 22 Apr 2025 16:09:49 -0400 Subject: [PATCH] Rolls 'duration_to_string' into pp --- peterborough.txt | 2 +- src/bin/pp.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/peterborough.txt b/peterborough.txt index d605535..a5e35d4 100644 --- a/peterborough.txt +++ b/peterborough.txt @@ -11,4 +11,4 @@ 24.143.184.98,Lindsay Cogeco 192.186.110.6,Belleville Cogeco 129.222.197.36,Belleville Starlink -192.168.0.50,Sign +192.168.1.50,Lindsay Sign diff --git a/src/bin/pp.rs b/src/bin/pp.rs index f63fba9..3f71308 100644 --- a/src/bin/pp.rs +++ b/src/bin/pp.rs @@ -18,6 +18,41 @@ use color_eyre::owo_colors::OwoColorize; use crossterm::style::Stylize; use log::debug; +pub fn duration_to_string(to_convert: Duration) -> String { + let mut total_seconds = to_convert.as_secs(); + let mut working_string = String::new(); + + if total_seconds > 86400 { + // days + let num_days = total_seconds / 86400; + working_string = format!("{} days", num_days); + total_seconds = total_seconds - (num_days * 86400); + } + + if total_seconds > 3600 { + // hours + let num_hours = total_seconds / 3600; + if num_hours > 0 { + working_string = format!("{} {} hours", working_string, num_hours); + total_seconds = total_seconds - (num_hours * 3600); + } + } + if total_seconds > 60 { + let num_minutes = total_seconds / 60; + if num_minutes > 0 { + working_string = format!("{} {} minutes", working_string, num_minutes); + total_seconds = total_seconds - (num_minutes * 60); + } + // minutes + } + + + working_string = format!("{} {} seconds", working_string, total_seconds); + + working_string +} + + struct PPState {} impl PPState { @@ -185,10 +220,11 @@ impl PPState { target_string.red().to_string() }; - println!("{} \t | {} \t | {}\t | Changed {}s ago", + println!("{} \t | {} \t | {}\t | Changed {} ago", target_string, current_result.alive, - current_result.last_rtt, time_since_last_change.as_secs() + current_result.last_rtt, + duration_to_string(time_since_last_change) ); } display_loop_start = now;