From 312488c1a6dc1501aeb0ff2a151b2f37d1432c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Fri, 8 Nov 2024 23:58:40 +0100 Subject: [PATCH] Use localtime for active session + don't split into days --- src/main.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 789e81b..eb0a178 100644 --- a/src/main.rs +++ b/src/main.rs @@ -133,18 +133,13 @@ async fn get_since(pool: &deadpool_diesel::sqlite::Pool, start: Option String { - let days = total_seconds / (24 * 3600); - let hours = (total_seconds % (24 * 3600)) / 3600; + let hours = total_seconds / 3600; let minutes = (total_seconds % 3600) / 60; - let seconds = total_seconds % 60; let mut parts = Vec::new(); - if days > 0 { parts.push(format!("{}d", days)); } if hours > 0 { parts.push(format!("{}h", hours)); } if minutes > 0 { parts.push(format!("{}m", minutes)); } - if seconds > 0 || parts.is_empty() { parts.push(format!("{}s", seconds)); } - parts.join(" ") } @@ -155,7 +150,7 @@ async fn get_metrics(State(pool): State, seconds: let active_sessions = conn.interact(|conn| work_periods::table.filter(work_periods::end_time.is_null()).select(( work_periods::start_time, - sql::("COALESCE(end_time, datetime('now'))") + sql::("COALESCE(end_time, datetime('now', 'localtime'))") )).load::<(NaiveDateTime, NaiveDateTime)>(conn)).await.map_err(internal_error)?.map_err(internal_error)?; let mut today = current_time.date_naive(); @@ -228,7 +223,6 @@ async fn start_tracking(State(pool): State, Json( async fn add_period(State(pool): State, Json(payload): Json) -> Result<(StatusCode, Json), (StatusCode, Json)> { let conn = pool.get().await.map_err(internal_error)?; - // insert your application logic here let res = conn .interact(move |conn| { diesel::insert_into(work_periods::table) @@ -240,8 +234,6 @@ async fn add_period(State(pool): State, Json(payl .map_err(internal_error)? .map_err(internal_error)?; - // this will be converted into a JSON response - // with a status code of `201 Created` Ok((StatusCode::CREATED, Json(res))) }