Implement closest and closestIndex in a type-safer(ish...) way
[SonOfLokstallBot.git] / src / tasks.php
index f58a7d4..5e37f6f 100644 (file)
@@ -11,7 +11,7 @@ $mondays = [
 ];
 $currentMonth = (int)(new DateTimeImmutable())->format('m');
 $currentDayOfMonth = closest((new DateTimeImmutable())->format('d'), $mondays);
-$currentWeekOfMonth = array_search($currentDayOfMonth, $mondays);
+$currentWeekOfMonth = closestIndex($currentDayOfMonth, $mondays);
 
 $taskLists = array_merge(
     isStartOfSeason($currentMonth, $currentDayOfMonth) ? [unlines(map(getStringAndCode)(getTasksForTheSeason(getSeason($currentMonth), $taskMatrix)))] : [],
@@ -43,7 +43,7 @@ $messages = zipWith(
     },
     // Magic. startOfSeason implies startofMonth so we get 2, start of month without start of season gives 1 and
     // a regular week (not the start of a season or month) gives 0. And this is how the indicies are ordered in the array.
-    $taskMessages[isStartOfSeason($currentMonth, $currentDayOfMonth) + isStartOfMonth($currentDayOfMonth)],
+    $taskMessages[(int)isStartOfSeason($currentMonth, $currentDayOfMonth) + (int)isStartOfMonth($currentDayOfMonth)],
     $taskLists
 );