- $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);