Start work week on Saturday

This commit is contained in:
Thomas Avé 2024-12-22 00:38:37 +01:00
parent 312488c1a6
commit 4c854f099a
1 changed files with 2 additions and 1 deletions

View File

@ -161,7 +161,8 @@ async fn get_metrics(State(pool): State<deadpool_diesel::sqlite::Pool>, seconds:
today = today - chrono::Duration::days(1); // If we are currently tracking, we haven't started today yet
}
let today_start = today.and_hms_opt(0, 0, 0);
let week_start = (today - chrono::Duration::days(current_time.weekday().num_days_from_monday() as i64)).and_hms_opt(0, 0, 0);
// We start our week on Saturday, the end of the previous week
let week_start = (today - chrono::Duration::days((current_time.weekday().num_days_from_sunday() - 1) as i64)).and_hms_opt(0, 0, 0);
let month_start = today.with_day(1).unwrap().and_hms_opt(0, 0, 0);
let year_start = today.with_day(1).unwrap().with_month(1).unwrap().and_hms_opt(0, 0, 0);