<?php
define('SATURDAY', 6);
define('SUNDAY', 7);
$holidays = [
'2024-01-01',
'2024-02-12',
'2024-02-13',
'2024-02-14',
'2024-02-15',
'2024-02-16',
'2024-04-04',
'2024-04-05',
'2024-05-01',
'2024-05-02',
'2024-05-03',
'2024-06-10',
'2024-09-16',
'2024-09-17',
'2024-10-01',
'2024-10-02',
'2024-10-03',
'2024-10-04',
'2024-10-07',
];
$weekendWorkdays = [
'2024-05-11',
'2024-09-14',
'2024-10-12',
];
$sundayWorkdays = [
'2024-02-04',
'2024-02-18',
'2024-04-07',
'2024-04-28',
'2024-09-29',
];
$dateInterval = DateInterval::createFromDateString('1 day');
function addWorkingDays($startDate, $daysToAdd, $holidays, $weekendWorkdays, $sundayWorkdays)
{
$startTimestamp = strtotime($startDate);
$workingDays = 0;
while ($daysToAdd > 0) {
$dateString = date('Y-m-d', $startTimestamp);
$dayOfWeek = date('N', $startTimestamp);
if ($dayOfWeek >= SATURDAY) {
if (isset($weekendWorkdays[$dateString])) {
$workingDays++;
}
elseif (isset($sundayWorkdays[$dateString])) {
$workingDays++;
}
} elseif (isset($holidays[$dateString])) {
} else {
$workingDays++;
$daysToAdd--;
}
$startTimestamp += 86400;
}
return date('Y-m-d', $startTimestamp - 86400);
}
$startDate = '2024-01-01';
$daysToAdd = 10;
$resultDate = addWorkingDays($startDate, $daysToAdd, array_flip($holidays), array_flip($weekendWorkdays), array_flip($sundayWorkdays));
echo "结果日期:$resultDate";