Possibilité de données un jour relatif ,choisir un cycle ,une heure etc etc
<?php
// Define an array to store the tasks
$tasks = array();
// Define a task with a relative day
$task = array(
'task_name' => 'Task 1',
'task_time' => '14:00',
'relative_day' => 'first saturday of this month',
'recurring' => true,
'interval' => 'daily'
);
array_push($tasks, $task);
// Execute a task
function executeTask($task) {
echo "Task " . $task['task_name'] . " has been executed at " . date('Y-m-d H:i:s') . "\n";
}
// Check if it's time to execute a task
foreach ($tasks as $task) {
// Check if the task has a relative day
if (isset($task['relative_day'])) {
$relativeDay = $task['relative_day'];
// Calculate the exact date based on the relative day
$exactDate = date('Y-m-d', strtotime($relativeDay . ' this month'));
// Check if the exact date is today
if ($exactDate == date('Y-m-d')) {
// Check if the current time matches the task time
if (date('H:i') == $task['task_time']) {
// Execute the task
executeTask($task);
// Check if the task is recurring
if ($task['recurring']) {
// Check the interval of the task
switch ($task['interval']) {
case 'daily':
$nextExactDate = date('Y-m-d', strtotime('tomorrow'));
break;
case 'weekly':
$nextExactDate = date('Y-m-d', strtotime('next week'));
break;
case 'monthly':
$nextExactDate = date('Y-m-d', strtotime($relativeDay . ' next month'));
break;
default:
$nextExactDate = date('Y-m-d', strtotime('tomorrow'));
break;
}
// Update the task with the next exact date
$task['relative_day'] = $nextExactDate;
}
}
}
} else {
// Check if the current time matches the task time
if (date('H:i') == $task['task_time']) {
// Execute the task
executeTask($task);
// Check if the task is recurring
if ($task['recurring']) {
// Check the interval of the task
switch ($task['interval']) {
case 'daily':
$nextExactDate = date('Y-m-d', strtotime('tomorrow'));
break;
case '