Kevin Lin wrote:[color=blue]
> I'm trying to come up with a function using PHP/MySQL (preferably a PHP only
> solution) to find the next time that matches a particular pattern, where the
> pattern is a combination of values or wildcards for minute, hour, day,
> weekday, month (like a predictive version of Unix's cron.)
>
> So, for example, I might ask for the next time that will match 8:00AM on a
> Monday, the next time that will match 15 minutes past midnight on the 1st of
> the month, or the next time it will be 11:59 on a Friday the 13th.
>
> It is quite easy to figure out whether or not a particular time matches
> these criteria, but I can see no way to predict when the next time it will
> happen.
>
> Any suggestions?[/color]
Check if today matches the criteria;
if it doesn't, check tomorrow;
if tomorrow doesn't match, check the next day;
.... ... ... ...
Yes, I know it's slow (next Thursday Christmas is due in 1520 days!)
<?php
$match = time();
while(true) {
if (day_month_week_check($match)) break;
/* ^^^^^^^^^^^^^^^^^^^^ TODO */
$match += 24*60*60;
}
/* now deal with hours and minutes :) */
?>
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |