From a0fcb5d4a82623eb54107c7cd31bd00d2b3ef92a Mon Sep 17 00:00:00 2001 From: Colin McKechney Date: Mon, 29 Dec 2025 13:08:23 -0500 Subject: [PATCH] Use human formatted time --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/modules/ttb.rs | 14 ++++++-------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4141415..75c96d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -306,6 +306,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "humantime" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424" + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -651,6 +657,7 @@ version = "0.1.0" dependencies = [ "chrono", "futures", + "humantime", "irc", "rand", "regex", diff --git a/Cargo.toml b/Cargo.toml index dbff4ea..155938b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,4 @@ futures = {version = "*"} tokio = {version = "*", features = ["full"]} regex = "1" rand = "0.8.5" +humantime = "2.3.0" diff --git a/src/modules/ttb.rs b/src/modules/ttb.rs index d86a5d9..243183f 100644 --- a/src/modules/ttb.rs +++ b/src/modules/ttb.rs @@ -1,6 +1,8 @@ use irc::proto::Message; use std::collections::VecDeque; -use chrono::{prelude::*, TimeDelta}; +use std::time::Duration; +use chrono::prelude::*; +use humantime; pub const PATTERN: &str = "^\\$ttb\\s*$"; pub const NAME: &str = "ttb"; @@ -15,13 +17,9 @@ pub fn time_to_baby(_: regex::Captures, _: &Message, _: &VecDeque) -> S let difference = local_time - birth_time; let completed_message; - /*if difference > TimeDelta::zero() { - completed_message = format!("{} {} until pnutz's baby is due!", difference.num_days(), if difference.num_days() > 1 { "days"} else {"day"} ); - } - else { - completed_message = "They're past due!".to_string(); - }*/ - completed_message = format!("He's {} days old!", difference.num_days()); + + let human_difference = humantime::format_duration(Duration::from_secs(difference.num_seconds() as u64)); + completed_message = format!("He's {} old!", human_difference.to_string()); completed_message