xref: /template/strap/vendor/dragonmantank/cron-expression/README.md (revision 37748cd8654635afbeca80942126742f0f4cc346)
1*37748cd8SNickeauPHP Cron Expression Parser
2*37748cd8SNickeau==========================
3*37748cd8SNickeau
4*37748cd8SNickeau[![Latest Stable Version](https://poser.pugx.org/mtdowling/cron-expression/v/stable.png)](https://packagist.org/packages/mtdowling/cron-expression) [![Total Downloads](https://poser.pugx.org/mtdowling/cron-expression/downloads.png)](https://packagist.org/packages/mtdowling/cron-expression) [![Build Status](https://secure.travis-ci.org/mtdowling/cron-expression.png)](http://travis-ci.org/mtdowling/cron-expression)
5*37748cd8SNickeau
6*37748cd8SNickeauThe PHP cron expression parser can parse a CRON expression, determine if it is
7*37748cd8SNickeaudue to run, calculate the next run date of the expression, and calculate the previous
8*37748cd8SNickeaurun date of the expression.  You can calculate dates far into the future or past by
9*37748cd8SNickeauskipping n number of matching dates.
10*37748cd8SNickeau
11*37748cd8SNickeauThe parser can handle increments of ranges (e.g. */12, 2-59/3), intervals (e.g. 0-9),
12*37748cd8SNickeaulists (e.g. 1,2,3), W to find the nearest weekday for a given day of the month, L to
13*37748cd8SNickeaufind the last day of the month, L to find the last given weekday of a month, and hash
14*37748cd8SNickeau(#) to find the nth weekday of a given month.
15*37748cd8SNickeau
16*37748cd8SNickeauInstalling
17*37748cd8SNickeau==========
18*37748cd8SNickeau
19*37748cd8SNickeauAdd the dependency to your project:
20*37748cd8SNickeau
21*37748cd8SNickeau```bash
22*37748cd8SNickeaucomposer require mtdowling/cron-expression
23*37748cd8SNickeau```
24*37748cd8SNickeau
25*37748cd8SNickeauUsage
26*37748cd8SNickeau=====
27*37748cd8SNickeau```php
28*37748cd8SNickeau<?php
29*37748cd8SNickeau
30*37748cd8SNickeaurequire_once '/vendor/autoload.php';
31*37748cd8SNickeau
32*37748cd8SNickeau// Works with predefined scheduling definitions
33*37748cd8SNickeau$cron = Cron\CronExpression::factory('@daily');
34*37748cd8SNickeau$cron->isDue();
35*37748cd8SNickeauecho $cron->getNextRunDate()->format('Y-m-d H:i:s');
36*37748cd8SNickeauecho $cron->getPreviousRunDate()->format('Y-m-d H:i:s');
37*37748cd8SNickeau
38*37748cd8SNickeau// Works with complex expressions
39*37748cd8SNickeau$cron = Cron\CronExpression::factory('3-59/15 2,6-12 */15 1 2-5');
40*37748cd8SNickeauecho $cron->getNextRunDate()->format('Y-m-d H:i:s');
41*37748cd8SNickeau
42*37748cd8SNickeau// Calculate a run date two iterations into the future
43*37748cd8SNickeau$cron = Cron\CronExpression::factory('@daily');
44*37748cd8SNickeauecho $cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s');
45*37748cd8SNickeau
46*37748cd8SNickeau// Calculate a run date relative to a specific time
47*37748cd8SNickeau$cron = Cron\CronExpression::factory('@monthly');
48*37748cd8SNickeauecho $cron->getNextRunDate('2010-01-12 00:00:00')->format('Y-m-d H:i:s');
49*37748cd8SNickeau```
50*37748cd8SNickeau
51*37748cd8SNickeauCRON Expressions
52*37748cd8SNickeau================
53*37748cd8SNickeau
54*37748cd8SNickeauA CRON expression is a string representing the schedule for a particular command to execute.  The parts of a CRON schedule are as follows:
55*37748cd8SNickeau
56*37748cd8SNickeau    *    *    *    *    *    *
57*37748cd8SNickeau    -    -    -    -    -    -
58*37748cd8SNickeau    |    |    |    |    |    |
59*37748cd8SNickeau    |    |    |    |    |    + year [optional]
60*37748cd8SNickeau    |    |    |    |    +----- day of week (0 - 7) (Sunday=0 or 7)
61*37748cd8SNickeau    |    |    |    +---------- month (1 - 12)
62*37748cd8SNickeau    |    |    +--------------- day of month (1 - 31)
63*37748cd8SNickeau    |    +-------------------- hour (0 - 23)
64*37748cd8SNickeau    +------------------------- min (0 - 59)
65*37748cd8SNickeau
66*37748cd8SNickeauRequirements
67*37748cd8SNickeau============
68*37748cd8SNickeau
69*37748cd8SNickeau- PHP 5.3+
70*37748cd8SNickeau- PHPUnit is required to run the unit tests
71*37748cd8SNickeau- Composer is required to run the unit tests