diff --git a/Cargo.toml b/Cargo.toml index 575a3d3..f3766bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" \ No newline at end of file diff --git a/src/bin/duration_to_string.rs b/src/bin/duration_to_string.rs index 2d49bd0..d455a10 100644 --- a/src/bin/duration_to_string.rs +++ b/src/bin/duration_to_string.rs @@ -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))); } \ No newline at end of file