From 95bb51dfd49ec9447119a18d63549c095a43e737 Mon Sep 17 00:00:00 2001 From: Wynd Date: Sun, 1 Sep 2024 10:57:24 +0300 Subject: [PATCH] Simplified the split-months option --- src/heatmap.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/heatmap.rs b/src/heatmap.rs index 20a70b8..23ee9c9 100644 --- a/src/heatmap.rs +++ b/src/heatmap.rs @@ -52,6 +52,16 @@ impl Heatmap { } while current_day <= until { + if split_months { + // If current day is the first of the month we add 2 weeks worth of empty space so + // months are more visible + if current_day.day0() == 0 { + 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 { @@ -74,19 +84,6 @@ impl Heatmap { None => heatmap.data[day_of_week as usize].push(0), } - 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; } @@ -94,13 +91,6 @@ impl Heatmap { heatmap } - fn last_day_of_month(&self, year: i32, month: u32) -> NaiveDate { - NaiveDate::from_ymd_opt(year, month + 1, 1) - .unwrap_or_else(|| NaiveDate::from_ymd(year + 1, 1, 1)) - .pred_opt() - .unwrap_or_default() - } - fn months_row(&self) -> String { let mut row = " ".to_string();