From 93852b91557d8328205e249d0466d169e434f6db Mon Sep 17 00:00:00 2001 From: Akulij Date: Sat, 7 Jun 2025 03:23:35 +0500 Subject: [PATCH] refactor timezoned time creation in botscript --- src/botscript.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/botscript.rs b/src/botscript.rs index c36f1c8..b912e22 100644 --- a/src/botscript.rs +++ b/src/botscript.rs @@ -955,15 +955,19 @@ impl RunnerConfig { } pub fn created_at(&self) -> DateTime { - self.created_at.at + TimeDelta::try_hours(self.config.timezone.into()).unwrap() + self.timezoned_time(self.created_at.at) + } + + pub fn timezoned_time(&self, dt: DateTime) -> DateTime { + dt + TimeDelta::try_hours(self.config.timezone.into()) + .unwrap_or_else(|| TimeDelta::try_hours(0).expect("Timezone UTC+0 does not exists")) } /// if None is returned, then garanteed that later calls will also return None, /// so, if you'll get None, no notifications will be provided later pub fn get_nearest_notifications(&self) -> Option { let start_time = self.created_at(); - let now = - chrono::offset::Utc::now() + TimeDelta::try_hours(self.config.timezone.into()).unwrap(); + let now = self.timezoned_time(chrono::offset::Utc::now()); let ordered = self .notifications