From 8a78d6fcb970d256f7645d6c0a6f02da987a2896 Mon Sep 17 00:00:00 2001 From: Joris Date: Tue, 31 Dec 2024 12:18:06 +0100 Subject: Fix getting start of week The 1st week of the year can begin some days the year before. --- src/gui/app.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/gui/app.rs') diff --git a/src/gui/app.rs b/src/gui/app.rs index 5469e53..76dff71 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -2,7 +2,7 @@ use gtk4 as gtk; use anyhow::Result; use async_channel::Sender; -use chrono::{Datelike, Duration, NaiveDate, Weekday}; +use chrono::{Datelike, Duration, NaiveDate}; use rusqlite::Connection; use std::rc::Rc; @@ -30,10 +30,7 @@ pub struct App { impl App { pub fn new(conn: Rc, app: >k::Application, tx: Sender) -> Result { let today = chrono::offset::Local::now().naive_local().date(); - // TODO: error handling - let start_date = - NaiveDate::from_isoywd_opt(today.year(), today.iso_week().week(), Weekday::Mon) - .unwrap(); + let start_date = today - Duration::days(today.weekday().num_days_from_monday().into()); let end_date = start_date + Duration::days(7 * 4 - 1); let events = db::events::list_non_recurring_between(&conn, start_date, end_date)?; -- cgit v1.2.3