Make sure to add 1 when using closestIndex to find the current week of the month
authorCameron Ball <cameron@cameron1729.xyz>
Tue, 1 Jan 2019 13:22:01 +0000 (21:22 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Fri, 4 Jan 2019 20:47:20 +0000 (04:47 +0800)
src/common.php
src/purjolok.php
src/tasks.php
src/unfinished.php

index 272b868..173bd32 100644 (file)
@@ -327,7 +327,6 @@ function getFilePathsForYear(int $year) {
 }
 
 function closestIndex($n, array $list) {
-    //return $list[closestIndex($n, $list)];
     $a = map(function(int $v) use ($n) : int {
             return (int)abs($v - $n);
         })
index 52e4a75..8b823de 100644 (file)
@@ -23,7 +23,7 @@ if ($between = between(reveal($message ?? ''), '[taskid]')) {
         (int)(new DateTimeImmutable('third monday of this month'))->format('d'),
         (int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
     ];
-    $currentWeekOfMonth = closestIndex($dt->format('d'), $mondays);
+    $currentWeekOfMonth = closestIndex($dt->format('d'), $mondays) + 1;
     $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), $currentWeekOfMonth);
     $completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
     $tasksForTheWeek = getTasksForTheWeek(
@@ -246,7 +246,7 @@ getTelegram()->addCommand(
                 (int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
             ];
             $currentMonth = (int)(new DateTimeImmutable())->format('m');
-            $currentWeekOfMonth = closestIndex((new DateTimeImmutable())->format('d'), $mondays);
+            $currentWeekOfMonth = closestIndex((new DateTimeImmutable())->format('d'), $mondays) + 1;
             $currentYear = (int)(new DateTimeImmutable())->format('Y');
             $tasksForTheWeek = getTasksForTheWeek(
                 $currentWeekOfMonth,
@@ -287,7 +287,7 @@ getTelegram()->addCommand(
                 (int)(new DateTimeImmutable('third monday of this month'))->format('d'),
                 (int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
             ];
-            $currentWeekOfMonth = closestIndex($dt->format('d'), $mondays);
+            $currentWeekOfMonth = closestIndex($dt->format('d'), $mondays) + 1;
 
             $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), $currentWeekOfMonth);
 
index 5e37f6f..5b11cc2 100644 (file)
@@ -11,7 +11,7 @@ $mondays = [
 ];
 $currentMonth = (int)(new DateTimeImmutable())->format('m');
 $currentDayOfMonth = closest((new DateTimeImmutable())->format('d'), $mondays);
-$currentWeekOfMonth = closestIndex($currentDayOfMonth, $mondays);
+$currentWeekOfMonth = closestIndex($currentDayOfMonth, $mondays) + 1;
 
 $taskLists = array_merge(
     isStartOfSeason($currentMonth, $currentDayOfMonth) ? [unlines(map(getStringAndCode)(getTasksForTheSeason(getSeason($currentMonth), $taskMatrix)))] : [],
index d8e58c9..de7b5b8 100644 (file)
@@ -15,7 +15,7 @@ $currentMonth = (int)(new DateTimeImmutable())->format('n');
 $currentDayOfMonth = closest((new DateTimeImmutable())->format('d'), $mondays);
 $currentSeason = getSeason($currentMonth);
 $currentYear = (int)(new DateTimeImmutable())->format('Y');
-$currentWeekOfMonth = closestIndex($currentDayOfMonth, $mondays);
+$currentWeekOfMonth = closestIndex($currentDayOfMonth, $mondays) + 1;
 
 $extractTasks = function($tasks, $path) {
     return array_merge($tasks, file_exists($path) ? lines(trim(file_get_contents($path))) : []);