format('w'); $potentialTodaySendTime = (clone $now)->setTime((int)$hour, (int)$minute, 0); if (in_array($todayDayOfWeek, $recurringDays) && $potentialTodaySendTime > $now) { // If today is a recurring day and the time hasn't passed yet, this is the next send time $nextSendTime = $potentialTodaySendTime; } else { // 2. Look for the next recurring day, starting from tomorrow for ($i = 1; $i <= 7; $i++) { // Check next 7 days $checkDate = (clone $now)->modify("+$i days"); $dayOfWeek = (int)$checkDate->format('w'); if (in_array($dayOfWeek, $recurringDays)) { $nextSendTime = (clone $checkDate)->setTime((int)$hour, (int)$minute, 0); break; // Found the earliest future recurring day } } } if ($nextSendTime === null) { throw new Exception('No se pudo determinar la próxima fecha de envío para la configuración recurrente proporcionada.'); } return $nextSendTime->format('Y-m-d H:i:s'); } } ?>