PHPackages                             savvywombat/ahora - 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. savvywombat/ahora

ActiveLibrary

savvywombat/ahora
=================

Interval calculator to help sum up multiple time intervals and display the total elapsed days/hours/minutes/seconds

1.1(4y ago)115MITPHPPHP ^7.4

Since Jun 28Pushed 4y ago1 watchersCompare

[ Source](https://github.com/SavvyWombat/ahora)[ Packagist](https://packagist.org/packages/savvywombat/ahora)[ Docs](https://github.com/SavvyWombat/ahora)[ RSS](/packages/savvywombat-ahora/feed)WikiDiscussions main Synced 2mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Ahora
=====

[](#ahora)

Time interval calculator.

Allows interval to be summed up and provides easy access the number of seconds/minutes/hours/days included in the interval.

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

[](#installation)

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

```
composer require savvywombat/ahora

```

Usage
-----

[](#usage)

### Creation

[](#creation)

You can create a new interval as a new instance, optionally passing in an [ISO8601 interval specification](https://en.wikipedia.org/wiki/ISO_8601#Durations):

```
use SavvyWombat\Ahora\Interval;

$interval = new Interval();
echo $interval->seconds; // outputs 0

$interval = new Interval("PT100D"); // 100 days
echo $interval->seconds; // outputs 8640000

```

Alternatively, you can create an interval from a PHP [DateInterval](http://php.net/manual/en/class.dateinterval.php), or from an interval specification with the following static methods:

```
use SavvyWombat\Ahora\Interval;

$date1 = new \DateTime("now");
$date2 = new \DateTime("2018-01-01");

$interval = Interval::createFromDateInterval($date1->diff($date2));

// or

$interval = Interval::createFromIntervalSpec("P28DT6H42M12S");

```

### Interval math

[](#interval-math)

Once you have an interval, you can easily add a number of seconds, minutes, hours, or days:

```
$interval = new Interval();

$interval->addSeconds(60); // equivalent to $interval->addMinutes(1);
$interval->addMinutes(60); // equivalent to $interval->addHours(1);
$interval->addHours(24); // equivalent to $interval->addDays(1);
$interval->addDays(7);

```

#### Adding intervals

[](#adding-intervals)

It is also possible to add intervals together:

```
$firstInterval = new Interval();
$firstInterval->addSeconds(45);

$secondInterval = new Interval();
$secondInterval->addSeconds(70);

$firstInterval->addInterval($secondInterval);

echo $firstInterval->seconds; // outputs 55
echo $firstInterval->minutes; // outputs 1

echo $firstInterval->realSeconds; // outputs 115

```

#### Subtracting intervals

[](#subtracting-intervals)

Similarly, you can subtract an interval from another:

```
$firstInterval = new Interval();
$firstInterval->addSeconds(45);

$secondInterval = new Interval();
$secondInterval->addSeconds(200);

$firstInterval->subInterval($secondInterval);

echo $firstInterval->seconds; // outputs -35
echo $firstInterval->minutes; // outputs -2

echo $firstInterval->realSeconds; // outputs -155

```

### Units and factors

[](#units-and-factors)

It is possible to inject additional units into the interval (such as weeks).

You can even modify or completely replace the units that the interval uses - with the limitation that one unit must be a multiple of `seconds`

```
$interval = new Interval();
$interval->addDays(10);

echo $interval->days; // outputs 10

$interval->setFactor('weeks', [7, 'days']);

echo $interval->realHours; // outputs 240
echo $interval->days; // outputs 3
echo $interval->weeks; // outputs 1

$interval->setFactor('days', [8, 'hours']);
$interval->setFactor('weeks', [5, 'days']);

echo $interval->realHours; // outputs 240
echo $interval->days; // outputs 2
echo $interval->weeks; // outputs 4

```

Obviously, changing these multipliers can have some drastic effects on the interval's outputs.

```
$interval = new Interval();

$oldFactors = $interval->getFactors(); // [
                                       //   'minutes' => [60, 'seconds'],
                                       //   'hours' => [60, 'minutes'],
                                       //   'days' => [24, 'hours'],
                                       // ]

$interval->setFactors([
    'microts' => [1, 'seconds'], // one unit must be related to seconds
    'arns' => [3600, 'microts'],
    'days' => [24, 'arns'],
    'cycles' => [360, 'days'],
]);

$interval->addDays(400);

echo $interval->cycles; // outputs 1
echo $interval->days; // outputs 40

```

Support
-------

[](#support)

Please report issues using the [GitHub issue tracker](https://github.com/SavvyWombat/ahora/issues). You are also welcome to fork the repository and submit a pull request.

Licence
-------

[](#licence)

Ahora is licensed under [The MIT License (MIT)](https://github.com/SavvyWombat/ahora/blob/master/LICENSE).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~558 days

Total

3

Last Release

1756d ago

PHP version history (2 changes)1.0PHP ^7.0

1.1PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/949f4b63b47c6f037d6ddd22ad3c34e67950655eb51a31d2b1f1205eac7005d7?d=identicon)[SavvyWombat](/maintainers/SavvyWombat)

---

Top Contributors

[![horuskol](https://avatars.githubusercontent.com/u/290549?v=4)](https://github.com/horuskol "horuskol (27 commits)")

---

Tags

datetimetimedateintervalsavvywombatsavvy wombatahora

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/savvywombat-ahora/health.svg)

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

###  Alternatives

[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[jenssegers/date

A date library to help you work with dates in different languages

1.8k11.2M79](/packages/jenssegers-date)[brick/date-time

Date and time library

3623.3M60](/packages/brick-date-time)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[carbonphp/carbon-doctrine-types

Types to use Carbon in Doctrine

213220.4M8](/packages/carbonphp-carbon-doctrine-types)

PHPackages © 2026

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