changeset 72:b9d9b4508898

Minor timezone fix for correctness
author Lewin Bormann <lbo@spheniscida.de>
date Wed, 17 Aug 2022 17:51:46 +0200
parents eade8c0055bf
children 50e4c86ab20c
files src/configdb.rs src/main.rs
diffstat 2 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/configdb.rs	Wed Aug 17 17:46:40 2022 +0200
+++ b/src/configdb.rs	Wed Aug 17 17:51:46 2022 +0200
@@ -21,7 +21,7 @@
 #[derive(Default, Clone, Debug, FromRow)]
 pub struct UserRecord {
     pub name: String,
-    pub tz_offset: i64,
+    pub tz_offset: i32,
 }
 
 pub struct ConfigDBSession<'p, DB: sqlx::Database>(pub &'p mut sqlx::pool::PoolConnection<DB>);
--- a/src/main.rs	Wed Aug 17 17:46:40 2022 +0200
+++ b/src/main.rs	Wed Aug 17 17:51:46 2022 +0200
@@ -206,6 +206,20 @@
         f = None;
     }
 
+    // Query user info.
+    let tz_offset = match ConfigDBSession(&mut config_conn)
+        .get_user_details(&lig.0)
+        .await
+    {
+        Ok(ur) => ur.tz_offset,
+        Err(e) => {
+            error!("Couldn't obtain user details: {}", e);
+            0
+        }
+    };
+    let includebots = includebots.unwrap_or(false);
+
+
     // Parameter treatment
     let duration = Duration::days(i64::from_str_radix(duration
         .unwrap_or("30"), 10).unwrap_or(30));
@@ -220,7 +234,7 @@
         })
         .unwrap_or(OffsetDateTime::now_utc() - duration);
 
-    let begin = from;
+    let begin = from.to_offset(time::UtcOffset::from_whole_seconds(tz_offset as i32).expect("UtcOffset"));
     let end = begin + duration;
     let ymd_format = time::format_description::parse("[year]-[month]-[day]").unwrap();
     let ymdhms_format = time::format_description::parse(
@@ -230,19 +244,6 @@
 
     // Chart rendering
 
-    // in seconds for this user.
-    let tz_offset = match ConfigDBSession(&mut config_conn)
-        .get_user_details(&lig.0)
-        .await
-    {
-        Ok(ur) => ur.tz_offset,
-        Err(e) => {
-            error!("Couldn't obtain user details: {}", e);
-            0
-        }
-    };
-    let includebots = includebots.unwrap_or(false);
-
     let ctx = logsdb::LogsQueryContext {
         domain: domain.clone(),
         from: begin,