$message = getTelegram()->getWebHookUpdates()->get('message') ? getTelegram()->getWebHookUpdates()->get('message')->get('text') : '';
if ($between = between(reveal($message ?? ''), '[taskid]')) {
- $dt = new DateTimeImmutable();
- $mondays = [
- (int)(new DateTimeImmutable('first monday of this month'))->format('d'),
- (int)(new DateTimeImmutable('second monday of this month'))->format('d'),
- (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) + 1;
- $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), $currentWeekOfMonth);
+ // The actual date/time when the script is called
+ $currentYear = (int)(new DateTimeImmutable())->format('Y');
+ $currentMonth = (int)(new DateTimeImmutable())->format('n');
+ $currentDay = (int)(new DateTimeImmutable())->format('d');
+
+ // The years/months/weeks that we are "rewinding" to, for calculations
+ $yearForThisWeek = getYearWeekBeginsIn($currentYear, $currentMonth, $currentDay);
+ $monthForThisWeek = getMonthWeekBeginsIn($currentYear, $currentMonth, $currentDay);
+ $seasonForThisWeek = getSeason($monthForThisWeek);
+ $weekNum = getWeekNumber($currentYear, $currentMonth, $currentDay);
+
+ $completedTasksFile = getFilePathForWeek($yearForThisWeek, $monthForThisWeek, $weekNum);
$completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
$tasksForTheWeek = getTasksForTheWeek(
- $currentWeekOfMonth,
- (int)$dt->format('m'),
+ $yearForThisWeek,
+ $monthForThisWeek,
+ $weekNum,
require 'taskMatrix.php'
);
protected $description = 'List tasks for this week';
public function handle($arguments) {
- $dt = new DateTimeImmutable();
- $directory = sprintf(
- "tasks/%s/%s/%s",
- $dt->format('Y'),
- $dt->format('F'),
- $dt->format('W')
- );
-
- $mondays = [
- (int)(new DateTimeImmutable('first monday of this month'))->format('d'),
- (int)(new DateTimeImmutable('second monday of this month'))->format('d'),
- (int)(new DateTimeImmutable('third monday of this month'))->format('d'),
- (int)(new DateTimeImmutable('fourth monday of this month'))->format('d'),
- ];
- $currentMonth = (int)(new DateTimeImmutable())->format('m');
- $currentWeekOfMonth = closestIndex((new DateTimeImmutable())->format('d'), $mondays) + 1;
+ // The actual date/time when the script is called
$currentYear = (int)(new DateTimeImmutable())->format('Y');
+ $currentMonth = (int)(new DateTimeImmutable())->format('n');
+ $currentDay = (int)(new DateTimeImmutable())->format('d');
+
+ // The years/months/weeks that we are "rewinding" to, for calculations
+ $yearForThisWeek = getYearWeekBeginsIn($currentYear, $currentMonth, $currentDay);
+ $monthForThisWeek = getMonthWeekBeginsIn($currentYear, $currentMonth, $currentDay);
+ $seasonForThisWeek = getSeason($monthForThisWeek);
+ $weekNum = getWeekNumber($currentYear, $currentMonth, $currentDay);
+
$tasksForTheWeek = getTasksForTheWeek(
- $currentWeekOfMonth,
- (int)$dt->format('m'),
+ $yearForThisWeek,
+ $monthForThisWeek,
+ $weekNum,
require 'taskMatrix.php'
);
- $completedTasksFile = getFilePathForWeek($currentYear, $currentMonth, $currentWeekOfMonth);
+ $completedTasksFile = getFilePathForWeek($yearForThisWeek, $monthForThisWeek, $weekNum);
$completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
if (!array_diff($tasksForTheWeek, $completedTasks)) {
protected $description = 'Mark a task as completed';
public function handle($arguments) {
- $dt = new DateTimeImmutable();
- $mondays = [
- (int)(new DateTimeImmutable('first monday of this month'))->format('d'),
- (int)(new DateTimeImmutable('second monday of this month'))->format('d'),
- (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) + 1;
+ // The actual date/time when the script is called
+ $currentYear = (int)(new DateTimeImmutable())->format('Y');
+ $currentMonth = (int)(new DateTimeImmutable())->format('n');
+ $currentDay = (int)(new DateTimeImmutable())->format('d');
- $completedTasksFile = getFilePathForWeek((int)$dt->format('Y'), (int)$dt->format('n'), $currentWeekOfMonth);
+ // The years/months/weeks that we are "rewinding" to, for calculations
+ $yearForThisWeek = getYearWeekBeginsIn($currentYear, $currentMonth, $currentDay);
+ $monthForThisWeek = getMonthWeekBeginsIn($currentYear, $currentMonth, $currentDay);
+ $seasonForThisWeek = getSeason($monthForThisWeek);
+ $weekNum = getWeekNumber($currentYear, $currentMonth, $currentDay);
$tasksForTheWeek = getTasksForTheWeek(
- $currentWeekOfMonth,
- (int)$dt->format('m'),
+ $yearForThisWeek,
+ $monthForThisWeek,
+ $weekNum,
require 'taskMatrix.php'
);
+ $completedTasksFile = getFilePathForWeek($yearForThisWeek, $monthForThisWeek, $weekNum);
$completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
+
+
if (!array_diff($tasksForTheWeek, $completedTasks)) {
$this->replyWithMessage([
'text' => getString('tasksAllCompleted')