PHPackages                             sportfinder/time - 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. sportfinder/time

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

sportfinder/time
================

Time management library to build complex business logic and agenda

v1.0.1(3y ago)36.5k↓57.1%[1 issues](https://github.com/sportfinder/time/issues)MITPHPPHP &gt;=7.1.3|8.\*CI failing

Since Feb 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/sportfinder/time)[ Packagist](https://packagist.org/packages/sportfinder/time)[ RSS](/packages/sportfinder-time/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

PHP Time management package
===========================

[](#php-time-management-package)

For several projects, I had to manage time, daily schedule, weekly schedule, and more. I need to be able to describe a weekly schedule and generate concrete timespans from the weekly schedule.

Those classes will help you:

- manage events or any object with a starting and ending points in time
- Compute mobile phone usages &amp; detailed consumption.
- define if a resource is available or not based on its usages
- detect availability/free time in a weekly schedule.
- generate optimized daily/weekly schedules

Project using this package:

- [SportFinder](https://www.sport-finder.com)
- [Natagora training platform](http://formations-nature.be/)

Inspired by

- My experience at [BePark](http://www.bepark.eu/)

Interfaces &amp; classes
------------------------

[](#interfaces--classes)

### Interfaces

[](#interfaces)

```
namespace SportFinder\Time;

interface DateSlotableInterface
{
    public function getStart(): ?\DateTime;
    public function getEnd(): ?\DateTime;
    public function toDateSlot(): DateSlotInterface;
}
```

```
namespace SportFinder\Time;

interface DateSlotInterface extends DateSlotableInterface
{
    public function contains($dateTimeOrDateSlot, $openLeft = false, $openRight = false): bool;
    public function equals(DateSlotInterface $dateSlot): bool;
    public function intersect(DateSlotableInterface $interval = null);
    public function subtract($dateSlot);
    public function getDuration($unit = Units::SECOND): int;
    public function hasTimeLeft(): bool;
    public function sub(\DateInterval $interval);
    public function add(\DateInterval $interval);
}
```

```
namespace SportFinder\Time;

interface ComparatorInterface
{
    public function isBefore($dateTimeOrDateSlot, $intervalOpen = false): bool;
    public function isAfter($dateTimeOrDateSlot, $intervalOpen = false): bool;
}
```

### Classes

[](#classes)

- **DateSlot**: contains complex &amp; useful business logic
- **Units**: final class that contains time units
- **DateTime**: a specialization of \\DateTime that implements ComparatorInterface and DateSlotableInterface

```
namespace SportFinder\Time;

class DateSlot implements DateSlotInterface, DurationInterface, ComparatorInterface{}
```

```
namespace SportFinder\Time;

class DateTime extends \DateTime implements ComparatorInterface, DateSlotableInterface{}
```

Usages
------

[](#usages)

### Creating the object

[](#creating-the-object)

```
$from = \DateTime::createFromFormat('Y-m-d', '2020-01-01');
$to = \DateTime::createFromFormat('Y-m-d', '2020-01-31');
$dateSlot1 = new DateSlot($from, $to);
$dateSlot2 = new DateSlot($from, $to);
$dateSlot1 == $dateSlot2; // true
```

### modifying an object

[](#modifying-an-object)

```
$dateSlot1 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2020-01-01'), \DateTime::createFromFormat('Y-m-d', '2020-01-02'));
$dateSlot2 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2020-01-02'), \DateTime::createFromFormat('Y-m-d', '2020-01-03'));
$dateSlot1 == $dateSlot2; // false
$dateSlot1->add(new \DateInterval('P1D'));
$dateSlot1 == $dateSlot2; // true
```

### comparing

[](#comparing)

```
// [2020-01-01, 2020-01-02]
$dateSlot1 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2020-01-01'), \DateTime::createFromFormat('Y-m-d', '2020-01-02'));
// [2020-01-03, 2020-01-04]
$dateSlot2 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2020-01-03'), \DateTime::createFromFormat('Y-m-d', '2020-01-04'));
$dateSlot1->isBefore($dateSlot2); // true
$dateSlot2->isAfter($dateSlot1); // true

// [2020-01-01, 2020-01-02]
$dateSlot1 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2020-01-01'), \DateTime::createFromFormat('Y-m-d', '2020-01-02'));
// [2020-01-02, 2020-01-03]
$dateSlot2 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2020-01-02'), \DateTime::createFromFormat('Y-m-d', '2020-01-03'));
$dateSlot1->isBefore($dateSlot2); // [2020-01-01, 2020-01-02] < [2020-01-02, 2020-01-03] ? false
$dateSlot1->isBefore($dateSlot2, true); // [2020-01-01, 2020-01-02[ < ]2020-01-02, 2020-01-03] ? true
```

### intersect

[](#intersect)

```
$dateSlot1 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2000-01-01'), \DateTime::createFromFormat('Y-m-d', '2000-01-31'));
$dateSlot2 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '1999-01-01'), \DateTime::createFromFormat('Y-m-d', '2000-01-31'));
$intersect = $dateSlot1->intersect($dateSlot2);
$expected = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2000-01-01'), \DateTime::createFromFormat('Y-m-d', '2000-01-31'));
$intersect == $expected; // True
```

### substract

[](#substract)

```
$year2000 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2000-01-01'), \DateTime::createFromFormat('Y-m-d', '2000-12-31'));
$february2000 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2000-02-01'), \DateTime::createFromFormat('Y-m-d', '2000-03-01'));
$november2000 = new DateSlot(\DateTime::createFromFormat('Y-m-d', '2000-11-01'), \DateTime::createFromFormat('Y-m-d', '2000-12-01'));
$year2000->subtract($february2000); // [[2000-01-01, 2000-02-01], [2000-03-01, 2000-12-31]]
$year2000->subtract([$february2000, $november2000]); // [[2000-01-01, 2000-02-01], [2000-03-01, 2000-11-01], [2000-12-01, 2000-12-31]]
```

Open questions &amp; reflexions
-------------------------------

[](#open-questions--reflexions)

- Should DateSlot be immutable? (cfr sub and add method)
- Should we create a ImmutableDateSlot class?

Contributing &amp; contact
--------------------------

[](#contributing--contact)

[SportFinder](https://www.sport-finder.com) is a belgian company. The platform is based on Symfony. We will publish as much as possible code to open source community. We are new to OpenSource contribution.

Fee free to contact us:

- by mail:
- personally  or

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Total

5

Last Release

1234d ago

Major Versions

v0.0.3 → v1.0.02023-02-17

PHP version history (3 changes)v0.0.1PHP ^7.1.3

v0.0.3PHP &gt;=7.1.3

v1.0.0PHP &gt;=7.1.3|8.\*

### Community

Maintainers

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

---

Top Contributors

[![walva](https://avatars.githubusercontent.com/u/3897363?v=4)](https://github.com/walva "walva (12 commits)")

---

Tags

agendaphptimetimeline

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sportfinder-time/health.svg)

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

PHPackages © 2026

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