Location: PHPKode > scripts > cron > cron/cron.demo.php
<!doctype html public "-//W3C//DTD HTML 4.0 //EN"> 
<html>
<!--
/*******************************************************************************
** Title.........: cron class demo page                                       **
** Summary.......: demonstrate the features of the cron class                 **
** Version.......: 0.2.6                                                      **
** Author........: Klaus P. Pieper <hide@address.com>               **
** Project home..: http://klaus_p.pieper.bei.t-online.de/                     **
** Filename......: class.cron.inc                                             **
** Copyright(C)..: 2002 Klaus P. Pieper                                       **
** Last changed..: 12 August 2002                                             **
** License.......: GNU Lesser General Public License (see below)              **
**                                                                            **
**  This library is free software; you can redistribute it and/or             **
**  modify it under the terms of the GNU Lesser General Public                **
**  License as published by the Free Software Foundation; either              **
**  version 2.1 of the License, or (at your option) any later version.        **
**                                                                            **
**  This library is distributed in the hope that it will be useful,           **
**  but WITHOUT ANY WARRANTY; without even the implied warranty of            **
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         **
**  Lesser General Public License for more details.                           **
                                                                              **
**  You should have received a copy of the GNU Lesser General Public          **
**  License along with this library; if not, write to the Free Software       **
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA **
*******************************************************************************/

/*******************************************************************************
**  Version history:
**  0.2.5: 12-Aug-2002: one more test case added
**  0.2.5: 08-Aug-2002: one more test case added
**  0.2.4: 29-Jul-2002: added several test cases
**  0.2.3: 25-Jul-2002: output re-formatted
**                      several new combinations added
**  0.2.2: 18-Jul-2002: first published version
*******************************************************************************/
-->
<head>
       <title>cron class demo page</title>
</head>
<body>
<h1>cron class demo page</h1><br>
<h2>by Klaus P. Pieper</h2><br>
<br>
<table border><tr><th>LAST</th><th>NOW</th><th>SPEC</th><th>RESULT</th></tr>
<tr><td colspan="4">The following combinations show a FALSE result</td></tr>
<?php
   //include("/myLib/class.cron.inc");
   include("class.cron.inc");

   // last later than reference: always FALSE
   demo("2002-07-16 01:00", "2002-07-16 00:30", "0 * * * *");
   demo(time(), "2002-07-16 00:30", "10-60 * * * *");
   
   // this returns FALSE (must specify last date)
   demo("", "2002-07-16 01:00", "0 * * * *");
   
   // last later than reference:
   // FALSE until end of 2029...
   demo("2029-12-31 01:00", time(), "0 * * * *");
   
   // FALSE returned until 01:00
   demo("2002-07-16 00:00", "2002-07-16 00:30", "0 * * * *");
   // FALSE returned until 03:00
   demo("2002-07-15 23:59", "2002-07-16 01:45", "0 3 * * *");

   // this returns FALSE based on days of week
   // specified days of week must be in between last and reference
   demo("2002-07-16 00:00", "2002-07-16 01:00", "0 * * * 0,1,3-6");
   demo("2002-07-16 00:00", "2002-07-19 10:54", "0 * * * 0,6,1");
   demo("2002-07-26 00:01", "2002-07-27 00:00", "0 * * * 1-5");
   demo("2002-08-09 00:01", "2002-08-11 00:00", "0 0 * * 1-5");
   
   // this returns FALSE because day and month are not yet passed
   // although day of week is ok
   demo("2002-07-16 00:00", "2002-07-19 10:54", "0 * 31 10 4");
   demo("2002-07-16 00:00", "2002-07-19 10:54", "0 * 31 10 *");

   // Same time is also not allowed
   demo("2002-07-27 00:00", "2002-07-27 00:00", "0 * * * *");

?>
<tr><td colspan="4">The following combinations show a TRUE result</td></tr>
<?php
   // this returns TRUE
   demo("2002-07-16 00:00", "2002-07-16 01:00", "0 * * * *");
   demo("2002-07-16 00:00", "2002-07-16 01:00", "0 * * * 2-4");
   demo("2002-07-15 23:59", "2002-07-16 00:01", "0 * * * *");
   demo("2002-07-15 23:59", "2002-07-16 03:01", "0 2 * * *");

   // this returns TRUE
   demo("2002-07-16 00:00", time(), "0 * * * *");
   demo("2002-07-16 00:00", time(), "0 * 0-31 * 0-6");

   // added in 0.2.5 - works with clas.cron.inc 0.2.7 and later
   demo("2002-08-07 05:10", "2002-08-08 05:05", "0 0 * * *");

   // this returns TRUE based on days of week
   // specified days of week must be in between last and reference
   demo("2002-07-16 00:00", "2002-07-16 01:00", "0 * * * 2-6");

   exit();

   function demo($vLast, $vNow, $sSpec)
   {
       $cronVal = cron::due($vLast, $vNow, $sSpec);
       $cronText = ($cronVal == TRUE) ? "TRUE" : "FALSE";
       if (is_integer($vNow))  $vNow = date("Y-m-d h:i", $vNow);
       if (is_integer($vLast)) $vLast = date("Y-m-d h:i", $vLast);
       echo "<tr><td>$vLast</td><td>$vNow</td><td>$sSpec</td><td>$cronText</td></tr>";
   }

?>
</table>
</body>
</html>
Return current item: cron