PHPackages                             philiprehberger/cron-expression-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. philiprehberger/cron-expression-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

philiprehberger/cron-expression-builder
=======================================

Fluent cron expression builder with human-readable methods

v1.2.0(2mo ago)138MITPHPPHP ^8.2CI passing

Since Mar 13Pushed 1mo agoCompare

[ Source](https://github.com/philiprehberger/cron-expression-builder)[ Packagist](https://packagist.org/packages/philiprehberger/cron-expression-builder)[ Docs](https://github.com/philiprehberger/cron-expression-builder)[ GitHub Sponsors](https://github.com/philiprehberger)[ RSS](/packages/philiprehberger-cron-expression-builder/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (6)Versions (6)Used By (0)

PHP Cron Expression Builder
===========================

[](#php-cron-expression-builder)

[![Tests](https://github.com/philiprehberger/cron-expression-builder/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/cron-expression-builder/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/18f4f0869571dda1e12c50871babd541bc2741c0a7fa57988a21c80e8ebc7a2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f63726f6e2d65787072657373696f6e2d6275696c6465722e737667)](https://packagist.org/packages/philiprehberger/cron-expression-builder)[![Last updated](https://camo.githubusercontent.com/421d6ae8d4a7b7407673c0435f58ba160bf67cf31bb4352413a470c8d6d2a1b4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7068696c69707265686265726765722f63726f6e2d65787072657373696f6e2d6275696c646572)](https://github.com/philiprehberger/cron-expression-builder/commits/main)

Fluent cron expression builder with human-readable methods.

Requirements
------------

[](#requirements)

- PHP 8.2+

Installation
------------

[](#installation)

```
composer require philiprehberger/cron-expression-builder
```

Usage
-----

[](#usage)

### Static Shortcuts

[](#static-shortcuts)

Use the `Cron` class for common schedules:

```
use PhilipRehberger\CronBuilder\Cron;

Cron::everyMinute();          // * * * * *
Cron::everyFiveMinutes();     // */5 * * * *
Cron::everyTenMinutes();      // */10 * * * *
Cron::everyFifteenMinutes();  // */15 * * * *
Cron::everyThirtyMinutes();   // */30 * * * *
Cron::hourly();               // 0 * * * *
Cron::hourlyAt(30);           // 30 * * * *
Cron::daily();                // 0 0 * * *
Cron::dailyAt('14:30');       // 30 14 * * *
Cron::weekly();               // 0 0 * * 0
Cron::weeklyOn(1, '09:00');   // 0 9 * * 1
Cron::monthly();              // 0 0 1 * *
Cron::monthlyOn(15, '08:00'); // 0 8 15 * *
Cron::yearly();               // 0 0 1 1 *
```

### Preset Intervals

[](#preset-intervals)

Use builder presets for common intervals:

```
use PhilipRehberger\CronBuilder\Cron;

Cron::custom()->everyQuarterHour()->build();                   // */15 * * * *
Cron::custom()->everyHalfHour()->build();                      // */30 * * * *
Cron::custom()->everyQuarterHour()->hour('9-17')->build();     // */15 9-17 * * *
Cron::custom()->weeklyOnDay('Monday')->minute('0')->hour('9')->build(); // 0 9 * * 1
```

### Custom Builder

[](#custom-builder)

Build complex expressions with the fluent builder:

```
use PhilipRehberger\CronBuilder\Cron;

$expression = Cron::custom()
    ->minute('*/10')
    ->hour('9-17')
    ->dayOfWeek('1-5')
    ->build();

// */10 9-17 * * 1-5
```

The builder implements `Stringable`, so you can use it directly in string contexts:

```
echo Cron::custom()->minute('0')->hour('*/2'); // 0 */2 * * *
```

### Next Run Date

[](#next-run-date)

Calculate the next execution time from a cron expression:

```
use PhilipRehberger\CronBuilder\CronExpression;

$expr = new CronExpression('0 9 * * 1');
$next = $expr->nextRunDate(); // Next Monday at 09:00

// With a specific starting datetime
$from = new \DateTimeImmutable('2026-03-22 10:00:00');
$next = $expr->nextRunDate($from); // 2026-03-23 09:00
```

### Next N Run Dates

[](#next-n-run-dates)

Calculate multiple upcoming execution times:

```
use PhilipRehberger\CronBuilder\CronExpression;
use PhilipRehberger\CronBuilder\CronScheduler;

// Via static method
$runs = CronScheduler::nextRuns('0 9 * * *', 5);

// Via CronExpression convenience method
$expr = new CronExpression('*/5 * * * *');
$runs = $expr->nextRuns(3, new \DateTimeImmutable('2026-03-22 10:00:00'));
// [2026-03-22 10:05, 2026-03-22 10:10, 2026-03-22 10:15]
```

### Overlap Detection

[](#overlap-detection)

Check if cron schedules produce overlapping execution times:

```
use PhilipRehberger\CronBuilder\CronScheduler;

// Check two expressions within a 24-hour window
CronScheduler::overlaps('0 9 * * *', '0 9 * * *'); // true
CronScheduler::overlaps('0 9 * * *', '0 14 * * *'); // false

// Find all overlaps among multiple expressions
$overlaps = CronScheduler::findOverlaps([
    'backup' => '0 2 * * *',
    'cleanup' => '0 2 * * *',
    'report' => '0 9 * * *',
], 24);
// [['expressions' => ['backup', 'cleanup'], 'time' => DateTimeImmutable]]
```

### Interval Analysis

[](#interval-analysis)

Analyze the timing intervals between cron runs:

```
use PhilipRehberger\CronBuilder\CronInterval;

CronInterval::averageInterval('*/5 * * * *'); // 300.0 (seconds)
CronInterval::minInterval('0 0 * * *');       // 86400.0 (seconds)
CronInterval::maxInterval('0 0 * * *');       // 86400.0 (seconds)
```

### Validator

[](#validator)

Validate cron expression syntax:

```
use PhilipRehberger\CronBuilder\CronValidator;

CronValidator::isValid('*/5 * * * *');   // true
CronValidator::isValid('60 * * * *');    // false
CronValidator::isValid('invalid');       // false
```

### Describer

[](#describer)

Get human-readable descriptions:

```
use PhilipRehberger\CronBuilder\CronDescriber;

CronDescriber::describe('* * * * *');      // "Every minute"
CronDescriber::describe('0 * * * *');      // "Every hour"
CronDescriber::describe('0 0 * * *');      // "Every day at midnight"
CronDescriber::describe('*/5 * * * *');    // "Every 5 minutes"
CronDescriber::describe('30 14 * * *');    // "Every day at 14:30"
CronDescriber::describe('0 0 * * 0');      // "Every Sunday at midnight"
CronDescriber::describe('0 0 1 * *');      // "First day of every month at midnight"
CronDescriber::describe('0 0 1 1 *');      // "Every year on January 1st at midnight"
```

API
---

[](#api)

MethodReturnsDescription`Cron::everyMinute()``string`Every minute (`* * * * *`)`Cron::everyFiveMinutes()``string`Every 5 minutes (`*/5 * * * *`)`Cron::everyTenMinutes()``string`Every 10 minutes (`*/10 * * * *`)`Cron::everyFifteenMinutes()``string`Every 15 minutes (`*/15 * * * *`)`Cron::everyThirtyMinutes()``string`Every 30 minutes (`*/30 * * * *`)`Cron::hourly()``string`Every hour at :00 (`0 * * * *`)`Cron::hourlyAt(int $minute)``string`Every hour at given minute`Cron::daily()``string`Every day at midnight (`0 0 * * *`)`Cron::dailyAt(string $time)``string`Every day at HH:MM`Cron::weekly()``string`Every Sunday at midnight`Cron::weeklyOn(int $day, string $time)``string`Weekly on given day at time`Cron::monthly()``string`First of month at midnight`Cron::monthlyOn(int $day, string $time)``string`Monthly on given day at time`Cron::yearly()``string`January 1st at midnight`Cron::custom()``CronBuilder`Start fluent builder`CronBuilder::everyQuarterHour()``self`Set minute to `*/15``CronBuilder::everyHalfHour()``self`Set minute to `*/30``CronBuilder::weeklyOnDay(string $dayName)``self`Set day of week by English name`CronExpression::nextRunDate(?DateTimeInterface $from)``DateTimeImmutable`Next execution time`CronExpression::nextRuns(int $count, ?DateTimeInterface $from)``array`Next N execution times`CronScheduler::nextRuns(string|CronExpression $expr, int $count, ?DateTimeInterface $from)``array`Next N run dates`CronScheduler::overlaps(string|CronExpression $a, string|CronExpression $b, int $windowHours, ?DateTimeInterface $from)``bool`Check if two schedules overlap`CronScheduler::findOverlaps(array $expressions, int $windowHours, ?DateTimeInterface $from)``array`Find all overlapping pairs`CronInterval::averageInterval(string|CronExpression $expr, int $sampleSize, ?DateTimeInterface $from)``float`Average seconds between runs`CronInterval::minInterval(string|CronExpression $expr, int $sampleSize, ?DateTimeInterface $from)``float`Minimum seconds between runs`CronInterval::maxInterval(string|CronExpression $expr, int $sampleSize, ?DateTimeInterface $from)``float`Maximum seconds between runs`CronValidator::isValid(string $expr)``bool`Validate cron syntax`CronDescriber::describe(string $expr)``string`Human-readable descriptionDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

Support
-------

[](#support)

If you find this project useful:

⭐ [Star the repo](https://github.com/philiprehberger/cron-expression-builder)

🐛 [Report issues](https://github.com/philiprehberger/cron-expression-builder/issues?q=is%3Aissue+is%3Aopen+label%3Abug)

💡 [Suggest features](https://github.com/philiprehberger/cron-expression-builder/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)

❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)

🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)

💻 [GitHub Profile](https://github.com/philiprehberger)

🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance88

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

5

Last Release

86d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (16 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

buildertimecronscheduleexpression

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-cron-expression-builder/health.svg)

```
[![Health](https://phpackages.com/badges/philiprehberger-cron-expression-builder/health.svg)](https://phpackages.com/packages/philiprehberger-cron-expression-builder)
```

###  Alternatives

[dragonmantank/cron-expression

CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due

4.7k498.1M666](/packages/dragonmantank-cron-expression)[league/period

Time range API for PHP

7335.7M22](/packages/league-period)[lorisleiva/cron-translator

Makes CRON expressions human-readable

3149.2M37](/packages/lorisleiva-cron-translator)[symfony/scheduler

Provides scheduling through Symfony Messenger

9012.8M97](/packages/symfony-scheduler)[florianv/business

DateTime calculations in business hours

360781.1k1](/packages/florianv-business)[mult1mate/cron-manager

Flexible cron tasks manager for MVC-type applications

40239.1k3](/packages/mult1mate-cron-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
