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

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

  1. Quartz Cron 触发器 Cron Expression 的格式

    转自:http://blog.csdn.net/yefengmeander/article/details/5985064 上一文中提到 Cron触发器可以接受一个表达式来指定执行JOB,下面看看这个 ...

  2. Cron Expression的用途

    对于一些MIS系统,DeadLine,需要用户自己制定事件规则,Cron Expression应该可以派上用场. Cron Maker: http://www.cronmaker.com/

  3. About the Cron Expression

    About the Cron Expression Cron is use in Linux for the time schedule Format Seconds Minutes Hours Da ...

  4. 【spring boot】使用定时任务@Scheduled 报错:Encountered invalid @Scheduled method 'dealShelf': Cron expression must consist of 6 fields (found 7 in "0 30 14 * * ? *")

    在spring boot中使用使用定时任务@Scheduled 报错: org.springframework.beans.factory.BeanCreationException: Error c ...

  5. What is corresponding Cron expression to fire in every X seconds, where X > 60? --转载

    原文地址:http://stackoverflow.com/questions/2996280/what-is-corresponding-cron-expression-to-fire-in-eve ...

  6. cron以及在laravel中使用cron

    yum install vixie-cron yum install crontabs /bin/systemctl restart crond.service #启动服务 /bin/systemct ...

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

    Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...

  8. Ternary Expression Parser

    Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...

  9. Leetcode: Ternary Expression Parser

    Given a string representing arbitrarily nested ternary expressions, calculate the result of the expr ...

随机推荐

  1. 2018面向对象程序设计(Java)第9周学习指导及要求

    2018面向对象程序设计(Java)第9周学习指导及要求(2018.10.25-2018.10.28)   学习目标 1.掌握java异常处理技术: 2.了解断言的用法: 3.了解日志的用途: 4.掌 ...

  2. ajax-》post

    1:最近写完前端,又写后端,jQuery的ajax已经用烂了,事实证明的确好用,再分享一下. data是后台echo的值,可以是数字,也可以是数组,用json_encode()包裹数组形式,前端接收要 ...

  3. ECharts-初始化方法参数不能传入jquery对象

    ECharts-初始化方法参数不能传入jquery对象

  4. 2.7、CDH 搭建Hadoop在安装(使用向导设置群集)

    步骤7:使用向导设置群集 完成“ 群集安装”向导后,“ 群集设置”向导将自动启动.以下部分将指导您完成向导的每个页面: 选择服务 分配角色 设置数据库 查看更改 首次运行命令 恭喜! 选择服务 “ 选 ...

  5. 响应式的账号登录界面模板完整代码,内置form表单和js控件

    响应式的账号登录界面模板,内置form表单和js控件 <!DOCTYPE html> <html lang="en"><head><met ...

  6. Oracle 存储过程例子返回记录集

    转载:https://www.cnblogs.com/mikalshao/articles/1454134.html Oracle 不支持批量查询,因此无法从一个命令返回多个结果集.使用存储过程时,返 ...

  7. pta l2-10(排座位)

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805066135879680 题意:给宴席排座位,有n个人,m个 ...

  8. Centos 7 下 Zabbix 3.4.x 服务搭建

    一.zabbix  介绍 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让 ...

  9. VIM常见命令

    1.删除所有数据 进入到第1行按下d,然后输入G回车,此时内容被全部清除 2.替换 :s/vivian/sky/ 替换当前行第一个 vivian 为 sky:s/vivian/sky/g 替换当前行所 ...

  10. centos6与centos7区别

    CentOS 6 vs CentOS 7的不同   (1)桌面系统[CentOS6] GNOME 2.x[CentOS7] GNOME 3.x(GNOME Shell) (2)文件系统[CentOS6 ...