From 0ca057c06455eab095b0a36d76359a82d197aa9f Mon Sep 17 00:00:00 2001 From: Akulij Date: Mon, 2 Jun 2025 16:43:53 +0500 Subject: [PATCH] create test for BotNotification --- src/botscript.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/botscript.rs b/src/botscript.rs index 64e46b1..9c0a9ab 100644 --- a/src/botscript.rs +++ b/src/botscript.rs @@ -893,4 +893,35 @@ mod tests { } ); } + + #[test] + fn test_notification_time() { + let botn = json!({ + "time": "18:00", + "filter": {"random": 2}, + "message": {"text": "some"}, + }); + let n: BotNotification = serde_json::from_value(botn).unwrap(); + println!("BotNotification: {n:#?}"); + let start_time = chrono::offset::Utc::now(); + // let start_time = chrono::offset::Utc::now() + TimeDelta::try_hours(5).unwrap(); + let start_time = start_time.with_hour(13).unwrap().with_minute(23).unwrap(); + let left = n.left_time(&start_time, &start_time); + let secs = left.as_secs(); + let minutes = secs / 60; + let hours = minutes / 60; + let minutes = minutes % 60; + println!("Left: {hours}:{minutes}"); + + let when_should = chrono::offset::Utc::now() + .with_hour(18) + .unwrap() + .with_minute(00) + .unwrap(); + + let should_left = (when_should - start_time).to_std().unwrap(); + let should_left = Duration::from_secs(should_left.as_secs()); + + assert_eq!(left, should_left) + } }