Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akki-io/cron-expression-generator
Generate cron expressions based on user inputs.
https://github.com/akki-io/cron-expression-generator
composer cron php
Last synced: 4 days ago
JSON representation
Generate cron expressions based on user inputs.
- Host: GitHub
- URL: https://github.com/akki-io/cron-expression-generator
- Owner: akki-io
- License: mit
- Created: 2021-05-26T18:08:50.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-05-27T14:59:02.000Z (over 3 years ago)
- Last Synced: 2024-04-25T15:01:53.409Z (7 months ago)
- Topics: composer, cron, php
- Language: PHP
- Homepage:
- Size: 153 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Cron Expression Generator
[![Latest Version](https://img.shields.io/github/release/akki-io/cron-expression-generator.svg?style=flat-square)](https://github.com/akki-io/cron-expression-generator/releases)
[![Build Status](https://img.shields.io/travis/akki-io/cron-expression-generator/master.svg?style=flat-square)](https://travis-ci.com/akki-io/cron-expression-generator)
[![Quality Score](https://img.shields.io/scrutinizer/g/akki-io/cron-expression-generator.svg?style=flat-square)](https://scrutinizer-ci.com/g/akki-io/cron-expression-generator)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![StyleCI](https://styleci.io/repos/371128023/shield?branch=master)](https://styleci.io/repos/371128023)
[![Total Downloads](https://img.shields.io/packagist/dt/akki-io/cron-expression-generator.svg?style=flat-square)](https://packagist.org/packages/akki-io/cron-expression-generator)Generate cron expressions based on user inputs.
## Installation
You can install the package via composer:
```bash
composer require akki-io/cron-expression-generator
```## Introduction
A CRON expression is a string representing the schedule for a particular command to execute.
The parts of a CRON schedule are as follows:```shell
* * * * *
- - - - -
| | | | |
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)
```| Cron Schedule | Package Request Mapping |
| ----------- | ----------- |
| min | minute |
| hour | hour |
| day of month | day_month |
| month | month |
| day of week | day_week |This package supports the following different options for each schedule.
| Option Type (*required) | Description | Nested Required Parameters |
| ----------- | ----------- | ----------- |
| ONCE | Generate cron once | int `at`, b/t the range of schedule |
| EVERY | Generate cron for every | int `every`, b/t the range of schedule |
| LIST | Generate cron based on the list of values | array `list` and int `list.*`, b/t the range of schedule |
| RANGE | Generate cron based on range | int `start` and int `end` both b/t the range of schedule |
| STEP | Generate cron based on step | int `every`, int `start` and int `end` all b/t the range of schedule |## Usage
You can set the `$options` array below based on the different options as outlined above.
```php
use AkkiIo\CronExpressionGenerator\CronExpressionGenerator;$options = [];
$cronExpression = (new CronExpressionGenerator($options))->generate();
```## Examples
**Generate cron expression for every minute**
```php
$options = [];$cronExpression = (new CronExpressionGenerator($options))->generate();
// * * * * *
```**Generate cron expression for once every hour**
```php
$options = [
'minute' => [
'type' => 'ONCE',
'at' => 0,
],
'hour' => [
'type' => 'EVERY',
'every' => 1,
],
];$cronExpression = (new CronExpressionGenerator($options))->generate();
// 0 */1 * * *
```**Generate cron expression for once every day at 10:15 AM**
```php
$options = [
'minute' => [
'type' => 'ONCE',
'at' => 15,
],
'hour' => [
'type' => 'ONCE',
'at' => 10,
],
];$cronExpression = (new CronExpressionGenerator($options))->generate();
// 15 10 * * *
```**Generate cron expression for once every weekday at 10:15 AM**
```php
$options = [
'minute' => [
'type' => 'ONCE',
'at' => 15,
],
'hour' => [
'type' => 'ONCE',
'at' => 10,
],
'day_week' => [
'type' => 'RANGE',
'start' => 1,
'end' => 5,
],
];$cronExpression = (new CronExpressionGenerator($options))->generate();
// 15 10 * * 1-5
```**Generate cron expression for once every month of day 22 at 10:15 AM**
```php
$options = [
'minute' => [
'type' => 'ONCE',
'at' => 15,
],
'hour' => [
'type' => 'ONCE',
'at' => 10,
],
'day_month' => [
'type' => 'ONCE',
'at' => 22,
],
];$cronExpression = (new CronExpressionGenerator($options))->generate();
// 15 10 22 * *
```**Generate cron expression for every Sunday at 10:15 AM**
```php
$options = [
'minute' => [
'type' => 'ONCE',
'at' => 15,
],
'hour' => [
'type' => 'ONCE',
'at' => 10,
],
'day_week' => [
'type' => 'ONCE',
'at' => 0,
],
];$cronExpression = (new CronExpressionGenerator($options))->generate();
// 15 10 * * 0
```**Generate cron expression for every year on Oct 22 at 10:15 AM**
```php
$options = [
'minute' => [
'type' => 'ONCE',
'at' => 15
],
'hour' => [
'type' => 'ONCE',
'at' => 10,
],
'day_month' => [
'type' => 'ONCE',
'at' => 22,
],
'month' => [
'type' => 'ONCE',
'at' => 10,
],
];$cronExpression = (new CronExpressionGenerator($options))->generate();
// 15 10 22 10 *
```### Testing
```bash
composer test
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Akki Khare](https://github.com/akki-io)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.