PHPackages                             rflex/period - 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. rflex/period

ActiveLibrary

rflex/period
============

Customized library for comparing periods easily. This is an extension of Carbon\\Period.

0.6.5(2y ago)012.4k↑80%PHP

Since May 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rflex-spa/period)[ Packagist](https://packagist.org/packages/rflex/period)[ RSS](/packages/rflex-period/feed)WikiDiscussions production Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (10)Used By (0)

`Period` is a library that extends `CarbonPeriod` to supply new customized methods.

You can find the `CarbonPeriod` documentation [here](https://carbon.nesbot.com/docs/#api-period).

Installation &amp; Usage
========================

[](#installation--usage)

```
composer require rflex/period
```

Import the class:

```
use Rflex\Period;
use Rflex\Event; // Extension of the Carbon class.
```

Testing
=======

[](#testing)

PHPUnit
-------

[](#phpunit)

```
./vendor/phpunit/phpunit/phpunit
```

PHPStan
-------

[](#phpstan)

```
./vendor/bin/phpstan analyse
```

Available methods
=================

[](#available-methods)

addDay() and addDays($days): void
---------------------------------

[](#addday-and-adddaysdays-void)

Add one or a number of days to the period.

```
$period->addDay(true, false); // Add a day to the start of the period.
$period->addDays(5, true, false); // Add five days to the start of the period.
```

subDay() and subDays($days): void
---------------------------------

[](#subday-and-subdaysdays-void)

Subtract one or a number of days to the period.

```
$period->subDay(false, true); // Subtract a day to the end of the period.
$period->subDays(3, false, true); // Subtract three days to the end of the period.
```

getSeconds(): int
-----------------

[](#getseconds-int)

Returns the total number of seconds of the period.

```
$period->getSeconds();
```

getMinutes(): int
-----------------

[](#getminutes-int)

Returns the total number of minutes of the period.

```
$period->getMinutes();
```

getHours(): int
---------------

[](#gethours-int)

Returns the total number of hours of the period.

```
$period->getHours();
```

union($period, $intersects): Period
-----------------------------------

[](#unionperiod-intersects-period)

Returns a new Period that is the sum of another two Periods. By default it will sum two periods without validating if they intersect. With the `$intersects` in `true` you can specify that you only need to sum two periods that intersect with each other.

```
$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$unifiedPeriod = $period->union($period2); // Returns a new unified Period.
```

intersection($period): Period
-----------------------------

[](#intersectionperiod-period)

Get the shared period between two other periods.

```
$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$intersection = $period->intersection($period2); // Returns a new intersected Period.
```

intersects($period): bool
-------------------------

[](#intersectsperiod-bool)

Checks if a period intersects with another.

```
$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$period->intersects($period2); // Returns true.
```

difference($period): array|null
-------------------------------

[](#differenceperiod-arraynull)

Returns the difference between two Periods. This function can return more than one Period if the original Period was cut in different pieces. `[totalLengthInSeconds, 'periods' => []]`

```
$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$period2 = Period::between(carbon::now(), Carbon::now()->addDays(2));
$unifiedPeriod = $period->difference($period2); // Returns an array.
```

differenceWithEvent($event, $point): int
----------------------------------------

[](#differencewitheventevent-point-int)

Returns the difference in seconds between a Period and an Event. The comparison is between the Event and a point of the Period. 0 = start, 1 = end.

```
$period = Period::between(Carbon::now(), Carbon::now()->addDay());
$event = Event::create(carbon::now());
$seconds = $period->differenceWithEvent($event); // Returns the difference between the two in seconds.
```

setLengthInSeconds($seconds): void
----------------------------------

[](#setlengthinsecondsseconds-void)

Set the length of the period in seconds from the start.

```
$period->setLengthInSeconds(3600);
```

setLengthInMinutes($minutes): void
----------------------------------

[](#setlengthinminutesminutes-void)

Set the length of the period in minutes from the start.

```
$period->setLengthInMinutes(700);
```

setLengthInHours($hours): void
------------------------------

[](#setlengthinhourshours-void)

Set the length of the period in hours from the start.

```
$period->setLengthInHours(48);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.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 ~11 days

Recently: every ~20 days

Total

9

Last Release

1017d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/28d3ed42660a1418f203eeaa1701702e6ed1713edf89f79f407a214b6012294c?d=identicon)[dmiranda-rflex](/maintainers/dmiranda-rflex)

---

Top Contributors

[![danshou](https://avatars.githubusercontent.com/u/682712?v=4)](https://github.com/danshou "danshou (31 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (6 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rflex-period/health.svg)

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

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k14.6M107](/packages/spatie-laravel-sitemap)[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k379.4k24](/packages/team-reflex-discord-php)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)

PHPackages © 2026

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