From: Cameron Ball Date: Tue, 1 Jan 2019 13:22:01 +0000 (+0800) Subject: Make sure to add 1 when using closestIndex to find the current week of the month X-Git-Url: http://git.cameron1729.xyz/?p=SonOfLokstallBot.git;a=commitdiff_plain;h=eae839f629b467676938c27a785fb6e38ac2fb39 Make sure to add 1 when using closestIndex to find the current week of the month --- diff --git a/src/common.php b/src/common.php index 272b868..173bd32 100644 --- a/src/common.php +++ b/src/common.php @@ -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); }) diff --git a/src/purjolok.php b/src/purjolok.php index 52e4a75..8b823de 100644 --- a/src/purjolok.php +++ b/src/purjolok.php @@ -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); diff --git a/src/tasks.php b/src/tasks.php index 5e37f6f..5b11cc2 100644 --- a/src/tasks.php +++ b/src/tasks.php @@ -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)))] : [], diff --git a/src/unfinished.php b/src/unfinished.php index d8e58c9..de7b5b8 100644 --- a/src/unfinished.php +++ b/src/unfinished.php @@ -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))) : []);