Proposal for "Date_Cron"

» Metadata » Status
  • Category: Date and Time
  • Proposer: Matt Scifo 
  • License: PHP License 3.0
» Description
This class is designed to parse cron-formatted strings and calculate execution times.

Cron-formatted strings are an efficient and useful way for applications to facilitate scheduling requirements.

Date_Cron's supported cron format contains 5 fields. From the CRONTAB(5) manpage...

  1. minute : 0-59
  2. hour : 0-23
  3. day of month : 1-31
  4. month : 1-12 (no names allowed)
  5. day of week : 0-7 (0 or 7 is Sun, no names allowed)

Date_Cron supports...

  1. Numbered lists: 5,6,7,8.
  2. Numbered ranges: 5-8 which evaluates to 5,6,7,8.
  3. Steps: 0-23/2 or */2.

  4. Numbers must be used for all fields. No textual names are allowed.


Sample Code:

<code>
// Call from an instantiated object.
$cron = new Date_Cron;
$date = $cron->getNextExecTime("30 10-12 1,2,5 * *", new Date("2004-05-01 10:45:05"));
print $date->getDate();
// prints "2004-05-01 11:30:00"

// Call statically.
$date = Date_Cron::getNextExecTime("30 10-12 1,2,5 * *");
print $date->getDate();


// Call from an instantiated object.
$cron = new Date_Cron;
$success = $cron->isDateWithinCron("30 10-12 1,2,5 * *", new Date("2004-05-01 10:45:05"));
// $success == false

// Call statically.
$success = Date_Cron::isDateWithinCron("30 10-12 1,2,5 * *", new Date("2004-05-01 11:30:05"));
// $success == true
</code>

Note: I contacted the maintainers of the Date package about integrating Date_Cron into the Date package but received no response.
» Dependencies » Links
  • Date
» Timeline » Changelog
  • First Draft: 2004-04-27
  • Proposal: 2004-04-27
  • Call for Votes: 2004-05-11
  • Voting Extended: 2004-05-19