New proof of concept for duration_to_string

Explicit declaration of duration_to_string
This commit is contained in:
Trevor Merritt 2025-04-21 07:55:40 -04:00
parent ee5986fedf
commit 03de859764
2 changed files with 6 additions and 4 deletions

View File

@ -8,3 +8,6 @@ env_logger = "0.11"
log = "0.4"
ansi_term = "0.12"
clap = { version = "4.5", features = ["derive"] }
[[bin]]
name = "duration_to_string"

View File

@ -1,6 +1,6 @@
use std::time::Duration;
fn duration_to_string(to_convert: Duration) -> String {
pub fn duration_to_string(to_convert: Duration) -> String {
let mut total_seconds = to_convert.as_secs();
let mut working_string = String::new();
@ -11,7 +11,6 @@ fn duration_to_string(to_convert: Duration) -> String {
total_seconds = total_seconds - (num_days * 86400);
}
if total_seconds > 3600 {
// hours
let num_hours = total_seconds / 3600;
@ -24,7 +23,7 @@ fn duration_to_string(to_convert: Duration) -> String {
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);
total_seconds = total_seconds - (num_minutes * 60);
}
// minutes
}
@ -34,9 +33,9 @@ fn duration_to_string(to_convert: Duration) -> String {
working_string
}
fn main() {
println!("1m 12s => {}", duration_to_string(Duration::from_secs(72)));
println!("1h 1m 12s => {}", duration_to_string(Duration::from_secs(3672)));
println!("1d 1h 1m 12s => {}", duration_to_string(Duration::from_secs(90072)));
println!("30d 1h 1m 12s => {}", duration_to_string(Duration::from_secs(2595672)));
}