diff --git a/habit.js b/habit.js index e229fc1..fc5c34d 100644 --- a/habit.js +++ b/habit.js @@ -43,7 +43,7 @@ function initializeWeeklyCalendar(selector, options) { var cal2 = new CalHeatMap(); var datethen = new Date(); - datethen.setMonth(datethen.getMonth() - 23); + datethen.setMonth(datethen.getMonth() - 24); // These two following calls are identicals // cal2.paint({ itemSelector: '#habit-cal' }); cal2.init({ diff --git a/habit.js b/habit.js index e229fc1..fc5c34d 100644 --- a/habit.js +++ b/habit.js @@ -43,7 +43,7 @@ function initializeWeeklyCalendar(selector, options) { var cal2 = new CalHeatMap(); var datethen = new Date(); - datethen.setMonth(datethen.getMonth() - 23); + datethen.setMonth(datethen.getMonth() - 24); // These two following calls are identicals // cal2.paint({ itemSelector: '#habit-cal' }); cal2.init({ diff --git a/habit.php b/habit.php index 560c539..7737e58 100644 --- a/habit.php +++ b/habit.php @@ -152,6 +152,7 @@ // Check if the word contains "#takeout" (case-insensitive) if (stripos($wordInLine, "#$filter") !== false) { $wordFound = true; + //echo "found: $line\n"; break; } } @@ -172,6 +173,7 @@ foreach ($dateOccurrences as $date => $count) { // Convert each date to the format $year-$weekNo $dateTime = new DateTime($date); + $dateTime->modify('this week sunday'); // Set to Sunday of the current week $yearWeek = $dateTime->format('Y-m-W'); // Add +1 for each date converted into $year-$weekNo as a key @@ -289,7 +291,7 @@ if ($date !== null) { // Calculate the difference in weeks // Check if the date is within the last 10 weeks - if (strtotime($date) < strtotime('-9 weeks')) { + if (strtotime($date) < strtotime('-11 weeks')) { continue; } } @@ -317,6 +319,7 @@ foreach ($dateOccurrences as $date => $count) { // Convert each date to the format $year-$weekNo $dateTime = new DateTime($date); + $dateTime->modify('this week sunday'); // Set to Sunday of the current week $yearWeek = $dateTime->format('Y-m-W'); // Add +1 for each date converted into $year-$weekNo as a key @@ -530,7 +533,8 @@ foreach ($dateOccurrences as $date => $count) { // Convert each date to the format $year-$weekNo $dateTime = new DateTime($date); - $yearWeek = $dateTime->format('Y-W'); + $dateTime->modify('this week sunday'); // Set to Sunday of the current week + $yearWeek = $dateTime->format('Y-m-W'); // Add +1 for each date converted into $year-$weekNo as a key if (isset($weeklyOccurrences[$yearWeek])) { @@ -544,9 +548,10 @@ $currentDate = date('Y-m-d'); while (strtotime($first) <= strtotime($currentDate)) { - $dateTime = new DateTime($currentDate); - $yearWeekKey = $dateTime->format('Y-W'); - $weeklyOccurrences[$yearWeekKey] = 0; + $dateTime = new DateTime($date); + $dateTime->modify('this week sunday'); // Set to Sunday of the current week + $yearWeek = $dateTime->format('Y-m-W'); + $weeklyOccurrences[$yearWeek] = 0; //echo $yearWeekKey; $currentDate = date('Y-m-d', strtotime($currentDate . ' -1 day')); } @@ -555,7 +560,7 @@ $consecutiveCount = 0; $maxConsecutiveCount = 0; - //ksort($weeklyOccurrences); + ksort($weeklyOccurrences); foreach ($weeklyOccurrences as $week => $value) { if ($value >= $multiplier) { @@ -1156,8 +1161,10 @@ $calHTML = ""; // Get current date $currentDate = new \DateTime(); + $currentDate->modify('this week sunday'); // Create an array to store months $months = []; + // Loop through the current month to 23 months ago and store in the array for ($i = 0; $i < 23; $i++) { @@ -1188,6 +1195,7 @@ foreach ($months as $monthData) { $year = $monthData['year']; $month = $monthData['month']; + $lastDay = date('t', strtotime("$year-$month-01")); $isoWeeksInMonth = $monthData['isoWeeks']; $calHTML .= '
'; @@ -1199,6 +1207,10 @@ foreach ($isoWeeksInMonth as $isoWeek) { $calHTML .= "
"; } + } else if( isSunday(new \DateTime("$year-$month-$lastDay")) ){ + foreach ($isoWeeksInMonth as $isoWeek) { + $calHTML .= "
"; + } } else { // Exclude the last ISO week when outputting weeks $keys = array_keys($isoWeeksInMonth);