PHPackages                             elstc/cakephp-time-interval - 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. [Database &amp; ORM](/categories/database)
4. /
5. elstc/cakephp-time-interval

ActiveCakephp-plugin[Database &amp; ORM](/categories/database)

elstc/cakephp-time-interval
===========================

TimeInterval type plugin for CakePHP

v3.2.0(4mo ago)31.2kMITPHPPHP &gt;=8.1CI passing

Since Apr 18Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/nojimage/cakephp-time-interval)[ Packagist](https://packagist.org/packages/elstc/cakephp-time-interval)[ RSS](/packages/elstc-cakephp-time-interval/feed)WikiDiscussions cake5 Synced 3w ago

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

TimeInterval plugin for CakePHP
===============================

[](#timeinterval-plugin-for-cakephp)

 [ ![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) ](LICENSE.txt) [ ![Build Status](https://camo.githubusercontent.com/0d6a67a5f006b3b291b38574f7c34f9b8082dd0c5632f40631683f81f8c1d015/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e6f6a696d6167652f63616b657068702d74696d652d696e74657276616c2f63692e796d6c3f7374796c653d666c61742d737175617265) ](https://github.com/nojimage/cakephp-time-interval/actions) [ ![Codecov](https://camo.githubusercontent.com/96b11734147c4c09801a9176d13393814b3e1059b8071b25ebfe62baff8abe88/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e6f6a696d6167652f63616b657068702d74696d652d696e74657276616c2e7376673f7374796c653d666c61742d737175617265) ](https://codecov.io/gh/nojimage/cakephp-time-interval) [ ![Latest Stable Version](https://camo.githubusercontent.com/ee0e25c30c1d723d9df26d68d5194a6a6c10947f8243999c031c113023b46d1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c7374632f63616b657068702d74696d652d696e74657276616c2e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/elstc/cakephp-time-interval)

This plugin provides `time_interval` custom type for MySQL's `TIME`, Postgres's `INTERVAL`, and provides `time_interval_int` custom type for seconds as `INTEGER`. This is a custom type to represent intervals, which CakePHP can treat as a `TimeInterval` object that inherits from `DateInterval`.

Version Map
-----------

[](#version-map)

CakePHP VersionPlugin VersionBranch5.x3.xcake54.x2.xcake43.x0.3.xcake3Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require elstc/cakephp-time-interval

```

### Load plugin

[](#load-plugin)

Load the plugin by adding the following statement in your project's `src/Application.php`:

```
$this->addPlugin('Elastic/TimeInterval');

```

Usage
-----

[](#usage)

### Add column definitions to Table class

[](#add-column-definitions-to-table-class)

```
use Cake\Database\Schema\TableSchema;

class WorkTimesTable extends Table
{
    protected function _initializeSchema(TableSchema $schema)
    {
        parent::_initializeSchema($schema);

        $schema->setColumnType('duration', 'time_interval');

        // If your column type is seconds as INTEGER, Use `time_interval_int` instead.
        $schema->setColumnType('duration_sec', 'time_interval_int');

        return $schema;
    }
}
```

### Add column validation to Table class

[](#add-column-validation-to-table-class)

Use `timeInterval` rule instead of `time`. The `timeInterval` rule is in the `timeInterval` validation provider.

```
use Cake\Validation\Validator;
use Elastic\TimeInterval\Validation\TimeIntervalValidation;

class WorkTimesTable extends Table
{
    public function validationDefault(Validator $validator)
    {
        // ...
        $validator->add('duration', 'timeInterval', [
            'rule' => 'timeInterval',
            'provider' => 'timeInterval',
        ]);

        return $validator;
    }
}
```

### Adding a mutator to the Entity class is useful

[](#adding-a-mutator-to-the-entity-class-is-useful)

```
use Cake\Database\Type;

class WorkTime extends Entity
{
    protected function _setDuration($value)
    {
        // convert to TimeInterval
        return Type::build('time_interval')->marshal($value);
    }
}

$workTime->duration = '00:15:00';
$workTime->duration = ($startTime)->diff($endTime); // $startTime, $endTime are DateTime objects.
$workTime->duration = 3600; // as seconds
```

NOTE
----

[](#note)

### MySQL TIME column limitation

[](#mysql-time-column-limitation)

[MySQL :: MySQL 8.0 Reference Manual :: 13.2.3 The TIME Type](https://dev.mysql.com/doc/refman/8.0/en/time.html)

```
By default, values that lie outside the TIME range but are otherwise valid are clipped to the closest endpoint of the range. For example,
'-850:00:00' and '850:00:00' are converted to '-838:59:59' and '838:59:59'. Invalid TIME values are converted to '00:00:00'.
Note that because '00:00:00' is itself a valid TIME value, there is no way to tell, from a value of '00:00:00' stored in a table,
whether the original value was specified as '00:00:00' or whether it was invalid.

```

### DateInterval / TimeInterval constructed with date parts will have incorrect time interpretation

[](#dateinterval--timeinterval-constructed-with-date-parts-will-have-incorrect-time-interpretation)

If you initialize DateInterval with date parts, time will not be interpreted correctly.

```
$workTime->duration = new DateInterval('PT75H4M5S'); // OK
$workTime->duration = new DateInterval('P1M2DT3H4M5S'); // can't get expected time
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance77

Regular maintenance activity

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity76

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 ~276 days

Recently: every ~290 days

Total

10

Last Release

137d ago

Major Versions

v0.2.0 → v2.0.02022-12-02

v2.0.1 → v3.0.02024-05-01

PHP version history (3 changes)v0.1.0PHP &gt;=5.6

v2.0.0PHP &gt;=7.2

v3.0.0PHP &gt;=8.1

### Community

Maintainers

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

---

Top Contributors

[![nojimage](https://avatars.githubusercontent.com/u/100564?v=4)](https://github.com/nojimage "nojimage (34 commits)")

---

Tags

cakephpcakephp-plugindatabaseintervaltime

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/elstc-cakephp-time-interval/health.svg)

```
[![Health](https://phpackages.com/badges/elstc-cakephp-time-interval/health.svg)](https://phpackages.com/packages/elstc-cakephp-time-interval)
```

###  Alternatives

[cakephp/bake

Bake plugin for CakePHP

11211.7M190](/packages/cakephp-bake)[dereuromark/cakephp-tools

A CakePHP plugin containing lots of useful and reusable tools

333972.2k49](/packages/dereuromark-cakephp-tools)[dereuromark/cakephp-shim

A CakePHP plugin to shim applications between major framework versions.

401.1M21](/packages/dereuromark-cakephp-shim)[dereuromark/cakephp-queue

The Queue plugin for CakePHP provides deferred task execution.

308914.0k25](/packages/dereuromark-cakephp-queue)[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1882.3M40](/packages/dereuromark-cakephp-ide-helper)[dereuromark/cakephp-databaselog

A CakePHP plugin for storing and viewing application logs in the database

44170.0k2](/packages/dereuromark-cakephp-databaselog)

PHPackages © 2026

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