WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

CronExpression_DayOfMonthField::getNearestWeekday() private WC 1.0

Get the nearest day of the week for a given day in a month

{} Это метод класса: CronExpression_DayOfMonthField{}

Хуков нет.

Возвращает

DateTime. Returns the nearest date

Использование

$result = CronExpression_DayOfMonthField::getNearestWeekday( $currentYear, $currentMonth, $targetDay );
$currentYear(int) (обязательный)
Current year
$currentMonth(int) (обязательный)
Current month
$targetDay(int) (обязательный)
Target day of the month

Код CronExpression_DayOfMonthField::getNearestWeekday() WC 5.8.0

private static function getNearestWeekday($currentYear, $currentMonth, $targetDay)
{
    $tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT);
    $target = new DateTime("$currentYear-$currentMonth-$tday");
    $currentWeekday = (int) $target->format('N');

    if ($currentWeekday < 6) {
        return $target;
    }

    $lastDayOfMonth = $target->format('t');

    foreach (array(-1, 1, -2, 2) as $i) {
        $adjusted = $targetDay + $i;
        if ($adjusted > 0 && $adjusted <= $lastDayOfMonth) {
            $target->setDate($currentYear, $currentMonth, $adjusted);
            if ($target->format('N') < 6 && $target->format('m') == $currentMonth) {
                return $target;
            }
        }
    }
}