method getNextDate documentation in bbn\Cron\Manager

Returns a SQL date for the next event given a frequency and a time to count from (now if 0).

function(string $frequency, int $from_time = 0) { if ((\strlen($frequency) >= 2)) { $letter = bbn\Str::changeCase(substr($frequency, 0, 1), 'lower'); $number = (int)substr($frequency, 1); $letters = ['y', 'm', 'w', 'd', 'h', 'i', 's']; if (in_array($letter, $letters, true) && ($number > 0)) { $time = time(); if (!$from_time) { $from_time = $time; } $year = intval(date('Y', $from_time)); $month = intval(date('n', $from_time)); $day = intval(date('j', $from_time)); $hour = intval(date('G', $from_time)); $minute = intval(date('i', $from_time)); $second = intval(date('s', $from_time)); $adders = []; foreach ($letters as $lt) { $adders[$lt] = 0; } $r = 0; $step = 0; if (!is_numeric($number)) { X::log($number, 'next_date'); } $test = mktime( $hour + ($letter === 'h' ? $number : 0), $minute + ($letter === 'i' ? $number : 0), $second + ($letter === 's' ? $number : 0), $month + ($letter === 'm' ? $number : 0), $day + ($letter === 'd' ? $number : ($letter === 'w' ? 7 * $number : 0)), $year + ($letter === 'y' ? $number : 0) ); $length = $test - $from_time; if ($test < $time) { $diff = $time - $test; $step = floor($diff / $length); } while ($r <= $time) { $step++; if ($letter === 'w') { $adders['d'] = $step * 7 * $number; } else { $adders[$letter] = $step * $number; } $r = mktime( $hour + $adders['h'], $minute + $adders['i'], $second + $adders['s'], $month + $adders['m'], $day + $adders['d'], $year + $adders['y'] ); } if ($r) { return date('Y-m-d H:i:s', $r); } } } return null; }

Returns a SQL date for the next event given a frequency and a time to count from (now if 0). BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.