To be honest I wasn't quite satisfied with the accepted and rewarded answer because I wanted to figure it out myself, not ending up with an external library and rewrite my code.
Given my cron like syntax as described in the question I've created a function to determine the next run time. I'd like to share it with the intention to help out others in the future if you're facing a similar problem. Maybe it points you into the direction you need.
Some demo cases
$cases = [
// Every minute
['i' => 90, 'H' => 90, 'd' => 90, 'm' => 90],
// Every 5th minute
['i' => 5, 'H' => 90, 'd' => 90, 'm' => 90],
// Every day at 02:15
['i' => 15, 'H' => 2, 'd' => 90, 'm' => 90],
// Every last day of the month at 15:20
['i' => 20, 'H' => 15, 'd' => 91, 'm' => 90],
// June 4th at 12:37
['i' => 37, 'H' => 12, 'd' => 4, 'm' => 6],
// Every minute between 04:00 and 05:00 at every day in October
['i' => 90, 'H' => 4, 'd' => 90, 'm' => 10],
];
Function:
function getNextRunTime($config) {
$minute = $config['i'];
$hour = $config['H'];
$day = $config['d'];
$month = $config['m'];
// Get minute
switch($minute) {
case 90 :
$nextMinute = date('i', strtotime('now + 1 minute'));
break;
default :
$nextMinute = $minute;
}
// Get hour
switch($hour) {
case 90 :
if($minute == 90 || $nextMinute > date('i')) {
$nextHour = date('H');
} else {
$nextHour = date('H', strtotime('now + 1 hour'));
}
break;
default :
$nextHour = $hour;
}
// Get day
switch($day) {
case 90 :
if($hour == 90 && $nextHour > date('H')) {
$nextDay = date('d');
} elseif($hour <> 90 && $nextHour <= date('H')) {
$nextDay = date('d', strtotime('now + 1 day'));
} else {
if($nextHour > date('H')) {
$nextDay = date('d');
} else {
if ($nextMinute > date('i')) {
$nextDay = date('d');
} else {
$nextDay = date('d', strtotime('now + 1 day'));
}
}
}
break;
case 91 :
if(date('t') == date('d')) {
if($nextHour > date('H')) {
$nextDay = date('d');
} elseif($nextHour == date('H') && $nextMinute > date('i')) {
$nextDay = date('d');
} else {
$nextDay = date('t', strtotime('now + 1 month'));
}
} else {
$nextDay = date('t');
}
break;
default :
$nextDay = $day;
}
// Get month
switch($month) {
case 90 :
if($day == 90 || $nextDay > date('d')) {
$nextMonth = date('m');
} elseif($nextDay == date('d')) {
if($hour == 90 || $nextHour > date('H')) {
$nextMonth = date('m');
} elseif($nextHour == date('H')) {
if($minute == 90 || $nextMinute > date('i')) {
$nextMonth = date('m');
} else {
$nextMonth = date('m', strtotime('now + 1 month'));
}
} else {
$nextMonth = date('m', strtotime('now + 1 month'));
}
} else {
$nextMonth = date('m', strtotime('now + 1 month'));
}
break;
default :
$nextMonth = $month;
}
// Get year
if($month == 90 || $nextMonth > date('m')) {
$nextYear = date('Y');
} elseif($nextMonth == date('m')) {
if($day == 90 || $nextDay > date('d')) {
$nextYear = date('Y');
} elseif($nextDay == date('m')) {
if($hour == 90 || $nextHour > date('H')) {
$nextYear = date('Y');
} elseif($nextHour == date('H')) {
if($minute == 90 || $nextMinute > date('i')) {
$nextYear = date('Y');
} else {
$nextYear = date('Y') + 1;
}
} else {
$nextYear = date('Y') + 1;
}
} else {
$nextYear = date('Y') + 1;
}
} else {
$nextYear = date('Y') + 1;
}
// Create the timestamp for the 'Next Run Time'
$nextRunTime = mktime($nextHour, $nextMinute, 0, $nextMonth, $nextDay, $nextYear);
// Check if the job has to run every minute, maybe a reset to d-m-Y h:00 is possible
if($nextRunTime > time() && $minute == 90) {
$tempNextRunTime = mktime($nextHour, 0, 0, $nextMonth, $nextDay, $nextYear);
if($tempNextRunTime > time()) {
$nextMinute = 0;
$nextRunTime = $tempNextRunTime;
}
}
// Check if the job has to run every hour, maybe a reset to d-m-Y 00:i is possible
if($nextRunTime > time() && $hour == 90) {
$tempNextRunTime = mktime(0, $nextMinute, 0, $nextMonth, $nextDay, $nextYear);
if($tempNextRunTime > time()) {
$nextHour = 0;
$nextRunTime = $tempNextRunTime;
}
}
// Check if the job has to run every day, maybe a reset to 1-m-Y H:i is possible
if($nextRunTime > time() && $day == 90) {
$tempNextRunTime = mktime($nextHour, $nextMinute, 0, $nextMonth, 1, $nextYear);
if($tempNextRunTime > time()) {
$nextRunTime = $tempNextRunTime;
}
}
// Return the Next Run Time timestamp
return $nextRunTime;
}
Output (execution time 23-09-2015, 11:12):
string '23-09-2015, 11:13' (length=17)
string '23-09-2015, 12:05' (length=17)
string '24-09-2015, 02:15' (length=17)
string '30-09-2015, 15:20' (length=17)
string '04-06-2016, 12:37' (length=17)
string '01-10-2015, 04:00' (length=17)
matchCronExpression()
andtrySchedule()