PHP Cron Expression Parser ( LARAVEL )

  

The PHP cron expression parser can parse a CRON expression, determine if it is due to run, calculate the next run date of the expression, and calculate the previous run date of the expression. You can calculate dates far into the future or past by skipping n number of matching dates.

The parser can handle increments of ranges (e.g. */12, 2-59/3), intervals (e.g. 0-9), lists (e.g. 1,2,3), W to find the nearest weekday for a given day of the month, L to find the last day of the month, L to find the last given weekday of a month, and hash (#) to find the nth weekday of a given month.

More information about this fork can be found in the blog post here. tl;dr - v2.0.0 is a major breaking change, and @dragonmantank can better take care of the project in a separate fork.

Installing

Add the dependency to your project:

composer require dragonmantank/cron-expression

Usage

<?php

require_once ‘/vendor/autoload.php‘;

// Works with predefined scheduling definitions
$cron = Cron\CronExpression::factory(‘@daily‘);
$cron->isDue();
echo $cron->getNextRunDate()->format(‘Y-m-d H:i:s‘);
echo $cron->getPreviousRunDate()->format(‘Y-m-d H:i:s‘);

// Works with complex expressions
$cron = Cron\CronExpression::factory(‘3-59/15 6-12 */15 1 2-5‘);
echo $cron->getNextRunDate()->format(‘Y-m-d H:i:s‘);

// Calculate a run date two iterations into the future
$cron = Cron\CronExpression::factory(‘@daily‘);
echo $cron->getNextRunDate(null, 2)->format(‘Y-m-d H:i:s‘);

// Calculate a run date relative to a specific time
$cron = Cron\CronExpression::factory(‘@monthly‘);
echo $cron->getNextRunDate(‘2010-01-12 00:00:00‘)->format(‘Y-m-d H:i:s‘);

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:

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

Requirements

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

原文地址:https://www.cnblogs.com/mouseleo/p/10248819.html

时间: 2024-08-03 19:42:20

PHP Cron Expression Parser ( LARAVEL )的相关文章

What is corresponding Cron expression to fire in every X seconds, where X &gt; 60? --转载

原文地址:http://stackoverflow.com/questions/2996280/what-is-corresponding-cron-expression-to-fire-in-every-x-seconds-where-x-60 Question: I want my jobs to execute in every X seconds, there's one to one matching between job and X. Also during runtime the

Quartz.Net Cron Expression

正如标题所示,文章主要是围绕Quartz.Net作业调度框架话题展开的,内容出自博主学习官方Examples的学习心得与体会,文中难免会有错误之处,还请指出得以指教. 前面了解了一些基本触发器构造作业调度的基础例子,接下来本篇会学习到关于Cron表达式的触发器. PS:ICronTrigger触发器所轮询的将是无限重复轮询. 一,还是先来看一下代码 using System; using System.Collections.Generic; using System.Linq; using S

Cron Expression

Cron 指计划任务,用7个以空格分开的域(字符串)表示任务在约定的时间执行. 7个域分别代表如下含义: Seconds | Minutes | Hours | DayOfMonths | Month | DayOfWeek | Year[Optional] 每个域均可使用值 ",". "-" . "*". "/", 其他选值如下: Seconds: 有效值范围 [0 - 59] Minutes: 有效值范围 [0 - 59]

Ternary Expression Parser Leetcode

Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is valid and only consists of digits 0-9, ?, :, T and F (T and F represent True and False resp

Ternary Expression Parser

Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is valid and only consists of digits 0-9, ?, :, T and F (T and F represent True and False resp

Leetcode: Ternary Expression Parser

Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is valid and only consists of digits 0-9, ?, :, T and F (T and F represent True and False resp

439. Ternary Expression Parser

ref: https://leetcode.com/problems/ternary-expression-parser/ Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is valid and only consists of di

[LeetCode] Ternary Expression Parser 三元表达式解析器

Given a string representing arbitrarily nested ternary expressions, calculate the result of the expression. You can always assume that the given expression is valid and only consists of digits 0-9, ?, :, T and F (T and Frepresent True and False respe

Asynchronous Jobs

Because Play is a web application framework, most of the application logic is done by controllers responding to HTTP requests. But sometimes you will need to execute some application logic outside of any HTTP request. It can be useful for initializat