2017 © Pedro Peláez
 

library cron-expression

A library to use cron expressions in PHP

image

mike-tralala/cron-expression

A library to use cron expressions in PHP

  • Sunday, April 1, 2018
  • by MikeTralala
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP Cron Expression Parser

pipeline status coverage report, (*1)

This cron-expression library can parse cron expressions like * * * * * and check if it is due or not. You are also able to determine the next or previous running dates., (*2)

This parser can handle anything the normal cron syntax accepts. with 1 exception and that are the named constructs (e.g. mon-thu or jan-dec)., (*3)

Installing

Add the dependency to your project:, (*4)

composer require mike-tralala/cron-expression

Usage

<?php

require_once __DIR__ . '/vendor/autoload.php';

use MikeTralala\CronExpression\Expression\DueDateCalculator;
use MikeTralala\CronExpression\Expression\Expression;

// Works with predefined definitions
$expression = new Expression(Expression::WEEKLY);
$expression->isDue();

$expression = new Expression(Expression::MINUTELY);
$expression->isDue();

// Works with complex definitions
$expression = new Expression('10-40/10 0 */5 1 4,5');
$expression->isDue();

// Calculating next running date
$calculator = new DueDateCalculator();
$expression = new Expression('*/2 * * * *');

$dueDates = $calculator->getNextDueDates($expression, 5, \DateTime::createFromFormat('Y-m-d H:i', '2018-01-01 00:00'));

echo $expression . PHP_EOL;
foreach ($dueDates as $dueDate) {
    echo $dueDate->format('Y-m-d H:i') . PHP_EOL;
}

// Output:

// */2 * * * *
// 2018-01-01 00:00
// 2018-01-01 00:02
// 2018-01-01 00:04
// 2018-01-01 00:06
// 2018-01-01 00:08

CRON Expressions

A CRON expression is a string representing the schedule for a particular command to execute. The parts of a CRON schedule are as follows:, (*5)

*    *    *    *    *
-    -    -    -    -
|    |    |    |    |
|    |    |    |    |
|    |    |    |    +----- day of week (0 - 6) (Sunday=0)
|    |    |    +---------- month (1 - 12)
|    |    +--------------- day of month (1 - 31)
|    +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)

Requirements

  • PHP 5.5+
  • PHPUnit is required to run the unit tests
  • Composer is required to run the unit tests

The Versions

01/04 2018

dev-master

9999999-dev

A library to use cron expressions in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Michael de Bie

01/04 2018

1.0.0

1.0.0.0

A library to use cron expressions in PHP

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

by Michael de Bie