})(['summer', 'winter', 'spring', 'autumn']));
}
-function closest($n, $list) {
- $a = array_filter($list, function($value) use ($n) {
- return $value <= $n;
- });
+function closestIndex($n, array $list) {
+ //return $list[closestIndex($n, $list)];
+ $a = map(function(int $v) use ($n) : int {
+ return (int)abs($v - $n);
+ })
+ ($list);
- arsort($a);
- return array_values($a)[0];
+ asort($a);
+ return array_keys($a)[0];
+}
+
+function closest($n, array $list) : int {
+ return $list[closestIndex($n, $list)];
}
function reveal($str) {
$penultimateBytes = array_filter(
(unpack('C*', $str)),
function($key) {
- return ($key + 1) % 4 == 0;
+ return ($key + 1) % 4 ==
+ 0;
},
ARRAY_FILTER_USE_KEY
);
(int)(new DateTimeImmutable('third monday of this month'))->format('d'),
(int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
];
- $closestMonday = closest($dt->format('d'), $mondays);
- $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), array_search($closestMonday, $mondays));
+ $currentWeekOfMonth = closestIndex($dt->format('d'), $mondays);
+ $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), $currentWeekOfMonth);
$completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
- $currentWeekOfMonth = array_search($closestMonday, $mondays);
$tasksForTheWeek = getTasksForTheWeek(
$currentWeekOfMonth,
(int)$dt->format('m'),
(int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
];
$currentMonth = (int)(new DateTimeImmutable())->format('m');
- $currentDayOfMonth = closest((new DateTimeImmutable())->format('d'), $mondays);
- $currentWeekOfMonth = array_search($currentDayOfMonth, $mondays);
+ $currentWeekOfMonth = closestIndex((new DateTimeImmutable())->format('d'), $mondays);
$currentYear = (int)(new DateTimeImmutable())->format('Y');
$tasksForTheWeek = getTasksForTheWeek(
$currentWeekOfMonth,
(int)(new DateTimeImmutable('third monday of this month'))->format('d'),
(int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
];
- $closestMonday = closest($dt->format('d'), $mondays);
+ $currentWeekOfMonth = closestIndex($dt->format('d'), $mondays);
- $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), array_search($closestMonday, $mondays));
+ $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), $currentWeekOfMonth);
$tasksForTheWeek = getTasksForTheWeek(
- array_search($closestMonday, $mondays),
+ $currentWeekOfMonth,
(int)$dt->format('m'),
require 'taskMatrix.php'
);
];
$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)))] : [],
},
// 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
);
$currentDayOfMonth = closest((new DateTimeImmutable())->format('d'), $mondays);
$currentSeason = getSeason($currentMonth);
$currentYear = (int)(new DateTimeImmutable())->format('Y');
-$currentWeekOfMonth = array_search($currentDayOfMonth, $mondays);
+$currentWeekOfMonth = closestIndex($currentDayOfMonth, $mondays);
$extractTasks = function($tasks, $path) {
return array_merge($tasks, file_exists($path) ? lines(trim(file_get_contents($path))) : []);
file_exists($filePathForWeek) ? lines(trim(file_get_contents($filePathForWeek))) : []
);
-//EOY => (EOM & EOW) & !EOS
+//EOY => (EOM & EOW) & !EOSx
//EOS => (EOM & EOW) & !EOY
$taskLists = array_merge(
isEndOfYear($currentYear, $currentMonth, $currentDayOfMonth) ? [unlines(map(getStringAndCode)($unfinishedForYear))] : [],