PHPackages                             jarnstedt/timerange - 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. jarnstedt/timerange

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

jarnstedt/timerange
===================

Compare and loop time ranges in PHP.

1.0.3(11y ago)42.9k22MITPHPPHP &gt;=5.3.0

Since May 19Pushed 10y ago3 watchersCompare

[ Source](https://github.com/jarnstedt/TimeRange)[ Packagist](https://packagist.org/packages/jarnstedt/timerange)[ Docs](https://github.com/jarnstedt/TimeRange)[ RSS](/packages/jarnstedt-timerange/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (5)Used By (2)

TimeRange [![](https://camo.githubusercontent.com/eff443ca3f938d7b834ce1c245ed608e04fc2d71a6dde328c200b0a289e72f5f/68747470733a2f2f7472617669732d63692e6f72672f6a61726e73746564742f54696d6552616e67652e706e67)](https://travis-ci.org/jarnstedt/TimeRange) [![SensioLabsInsight](https://camo.githubusercontent.com/15210060f64715c0cb96a9b8b9ab9ebfa10d5300e36cb49315d8176da27c6c9c/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f37633736613562302d383036652d346530382d383834382d6664313835333631376164312f6d696e692e706e67)](https://insight.sensiolabs.com/projects/7c76a5b0-806e-4e08-8848-fd1853617ad1)
===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#timerange--)

Compare and loop time ranges in PHP.

Install
-------

[](#install)

For manual install copy timerange.php to your project.

Install with Composer:

```
composer.phar require jarnstedt/timerange

```

Examples
--------

[](#examples)

### Creating a TimeRange object

[](#creating-a-timerange-object)

```
use TimeRange;

// Create a new TimeRange
$timeRange1 = new TimeRange('2013-03-31 00:00:00', '2013-04-01 01:09:00');

// You can also use PHP DateTime objects
$start = new DateTime('2000-01-01');
$end = new DateTime('2000-01-05');
$timeRange2 = new TimeRange($start, $end);
```

### Looping TimeRange

[](#looping-timerange)

TimeRange supports looping minutes, hours, days and months.

```
// Echo all days in time range
foreach ($timeRange1->getDays() as $datetime) {
  echo $datetime->format('Y-m-d')."";
}

// Echo every other day in time range backwards
foreach ($timeRange1->getDays(2, TimeRange::BACKWARD) as $datetime) {
  echo $datetime->format('Y-m-d')."";
}

// Echo all minutes
foreach ($timeRange1->getMinutes() as $datetime) {
  echo $datetime->format('Y-m-d H:i')."";
}
```

### Check if two TimeRanges overlap

[](#check-if-two-timeranges-overlap)

```
$timeRange1 = new TimeRange('2013-03-31 00:00', '2013-04-01 01:09');
$timeRange2 = new TimeRange('2013-01-01 12:30', '2013-01-05 14:00');

if ($timeRange1->overlaps($timeRange2)) {
  echo "Ranges overlap";
}

// Check if date overlaps the TimeRange
if ($timeRange1->overlaps("2013-04-01", TimeRange::DAY)) {
  ...
}
```

### Changing start or end of the range

[](#changing-start-or-end-of-the-range)

```
$timeRange = new TimeRange('2013-03-31 00:00', '2013-04-01 01:09');
$timeRange->setStart('2013-02-28');
$timeRange->setEnd('2013-03-03');
```

Running unit tests
------------------

[](#running-unit-tests)

Download phpunit from  and in project directory run:

```
php phpunit.phar

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 94.6% 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 ~53 days

Total

4

Last Release

4220d ago

### Community

Maintainers

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

---

Top Contributors

[![jarnstedt](https://avatars.githubusercontent.com/u/4012380?v=4)](https://github.com/jarnstedt "jarnstedt (70 commits)")[![FusionClock](https://avatars.githubusercontent.com/u/6985176?v=4)](https://github.com/FusionClock "FusionClock (2 commits)")[![Juhku](https://avatars.githubusercontent.com/u/1476859?v=4)](https://github.com/Juhku "Juhku (2 commits)")

---

Tags

datetimecomparetimedaterangeperiod

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jarnstedt-timerange/health.svg)

```
[![Health](https://phpackages.com/badges/jarnstedt-timerange/health.svg)](https://phpackages.com/packages/jarnstedt-timerange)
```

###  Alternatives

[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[tplaner/when

Date/Calendar recursion library.

5261.0M5](/packages/tplaner-when)[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)[kartik-v/php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.

461.5M3](/packages/kartik-v-php-date-formatter)

PHPackages © 2026

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