From 5622df82a998852b3a493f606136417f489be23b Mon Sep 17 00:00:00 2001 From: Wynd Date: Sun, 1 Sep 2024 10:52:10 +0300 Subject: [PATCH] Fixed the split-months heatmap being 1 day off --- src/heatmap.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/heatmap.rs b/src/heatmap.rs index 0bb6dc2..20a70b8 100644 --- a/src/heatmap.rs +++ b/src/heatmap.rs @@ -52,19 +52,6 @@ impl Heatmap { } while current_day <= until { - if split_months { - let last_day_of_month = - heatmap.last_day_of_month(current_day.year_ce().1 as i32, current_day.month()); - - // If current day is the last of the month we add 2 weeks worth of empty space so - // months are more visible - if last_day_of_month == current_day { - for i in 0..14 { - heatmap.data[(i as usize) % 7].push(-1); - } - } - } - let month_name = current_day.format("%b").to_string(); if current_day == since { @@ -86,7 +73,20 @@ impl Heatmap { } None => heatmap.data[day_of_week as usize].push(0), } - // println!("{} {value:?}", current_day); + + if split_months { + let last_day_of_month = + heatmap.last_day_of_month(current_day.year_ce().1 as i32, current_day.month()); + + // If current day is the last of the month we add 2 weeks worth of empty space so + // months are more visible + if last_day_of_month == current_day { + for i in 0..14 { + heatmap.data[(i as usize) % 7].push(-1); + } + } + } + current_day += Duration::days(1); day_of_week = current_day.weekday().num_days_from_monday() % 7; }