PHPackages                             zeeproject/date-range - 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. zeeproject/date-range

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

zeeproject/date-range
=====================

Date range implementation

0.5.0(2y ago)11.3k[2 issues](https://github.com/slavcodev/date-range/issues)[3 PRs](https://github.com/slavcodev/date-range/pulls)MITPHPPHP ~8.2.0CI passing

Since Nov 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/slavcodev/date-range)[ Packagist](https://packagist.org/packages/zeeproject/date-range)[ Docs](https://github.com/zee/date-range)[ RSS](/packages/zeeproject-date-range/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (5)Dependencies (5)Versions (9)Used By (0)

Date Range
==========

[](#date-range)

[![Tests status](https://github.com/zee/date-range/workflows/phpunit/badge.svg)](https://github.com/zee/date-range)[![Code Coverage](https://camo.githubusercontent.com/be168d2e6db10a4400e64d7ae3710c0e0acf33df7e6987dcb54489fd031ec5d7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7a65652f646174652d72616e67652e7376673f6c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/zee/date-range/code-structure)[![Quality Score](https://camo.githubusercontent.com/ce820c18dff550d273736e3c640f98e22eaec5f8730de6db74b703f785ce55d6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7a65652f646174652d72616e67652e7376673f6c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/zee/date-range)[![GitHub issues](https://camo.githubusercontent.com/08d6e1170b2cf7c7b37c38990248bd133f70e8e1092f94af76f7597845925f58/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f7a65652f646174652d72616e67652e7376673f6c6f676f3d676974687562)](https://github.com/zee/date-range/issues)[![Software License](https://camo.githubusercontent.com/7dc50c26ab39f140a00c49f5d748bb72cd21bc47191bb69a3c701ce7f24e82a2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7a65652f646174652d72616e6765)](LICENSE)[![Latest Version on Packagist](https://camo.githubusercontent.com/e73965aa1b1403b1b3779a1595bc927cb9ce0ef5f2e87367ac97e719d32be469/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a656570726f6a6563742f646174652d72616e67652e7376673f6c6162656c3d4c6174657374)](https://packagist.org/packages/zeeproject/date-range)

Implementation of the **Date Range** missing in PHP.

Install
-------

[](#install)

Using [Composer](https://getcomposer.org)

```
composer require zeeproject/date-range
```

Usage
-----

[](#usage)

### DateRange - value object

[](#daterange---value-object)

Instantiating value object and accessing properties:

```
$range = new DateRange(new DateTime('-1 day'), new DateTime('+1 day'));
// Checking if range has start date
$range->hasStartDate();
// Accessing range start date
$range->getStartDate()->format('c');
// Checking if range has end date
$range->hasEndDate();
// Accessing range end date
$range->getEndDate()->format('c');
// Checking if range is finite
$range->isFinite();
// Checking if range already started
$range->isStarted();
// Checking if range already ended
$range->isEnded();
// Checking if range started on specific date
$range->isStartedOn(new DateTime());
// Checking if range ended on specific date
$range->isEndedOn(new DateTime());
// Accessing range duration in seconds
$range->getTimestampInterval();
// Accessing range interval
$range->getDateInterval()->format('%s');
// Printing
echo $range;
// Representing as JSON
json_encode($range);
```

Iterating over the range:

```
$range = new DateRange(new DateTime('-1 day'), new DateTime('+1 day'));

foreach ($range->getDatePeriod(new DateInterval('P1D')) as $date) {
    echo $date->format('Y-m-d');
}
```

Splitting range into smaller ranges:

```
$range = new DateRange(new DateTime('-1 day'), new DateTime('+1 day'));

foreach ($range->split(new DateInterval('P1D')) as $range) {
    echo $range;
}
```

Date range is immutable, any changes resulting to new object:

```
$initial = new DateRange(new DateTime('-1 day'), new DateTime('+1 day'));
$actual = $initial->setStartDate(new DateTime('now'));
if ($initial === $actual) {
    throw new LogicException('Oh, ah');
}
```

### DateRangeProvider - the date ranges builder.

[](#daterangeprovider---the-date-ranges-builder)

Using builder to create new range with specific rules:

```
class RangeForYear implements DateRangeProvider
{
    /**
     * @var int
     */
    private $year;

    /**
     * @param int $year
     */
    public function __construct(int $year)
    {
        $this->year = $year;
    }

    public function getDateRange(): DateRangeInterface
    {
        return new DateRange(
            new DateTimeImmutable(DateTimeImmutable::createFromFormat('c', "{$this->year}-01-01T00:00:00Z")),
            new DateTimeImmutable(DateTimeImmutable::createFromFormat('c', "{$this->year}-12-31T23:59:59Z"))
        );
    }
}
```

Your classes might depend on range provider instead of `DateRange`, useful when predefined ranges are more meaningful than range interface:

```
class ReportCalculator
{
    public function calculate(DateRangeProvider $provider)
    {
        echo $provider->getDateRange();
    }
}

$calculator->calculate(new RangeForYear(2017));
$calculator->calculate(new RangeForQuarter(2017));
$calculator->calculate(new RangeForMonth(2017));
```

Even your class might require concrete range contract:

```
class ReportCalculator
{
    public function calculate(FiniteDateRangeProvider $provider)
    {
        echo $provider->getDateRange();
    }
}
```

Testing
-------

[](#testing)

```
phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) and [CODE OF CONDUCT](.github/CODE_OF_CONDUCT.md) for more details.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 71.8% 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 ~501 days

Total

5

Last Release

1093d ago

PHP version history (2 changes)0.0.1PHP ^7.1

0.5.0PHP ~8.2.0

### Community

Maintainers

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

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (102 commits)")[![slavcodev](https://avatars.githubusercontent.com/u/757721?v=4)](https://github.com/slavcodev "slavcodev (40 commits)")

---

Tags

date-timedaterangedate-range

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/zeeproject-date-range/health.svg)

```
[![Health](https://phpackages.com/badges/zeeproject-date-range/health.svg)](https://phpackages.com/packages/zeeproject-date-range)
```

###  Alternatives

[kartik-v/yii2-date-range

An advanced Yii 2 date range picker input for based on bootstrap-daterangepicker plugin.

894.4M42](/packages/kartik-v-yii2-date-range)[openpsa/ranger

Formatter for date and time ranges with i18n support

76177.6k3](/packages/openpsa-ranger)[studioespresso/craft-date-range

Date range field

1222.6k1](/packages/studioespresso-craft-date-range)

PHPackages © 2026

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