PHPackages                             tmihalicka/php-duration - 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. tmihalicka/php-duration

Abandoned → [monadial/php-duration](/?search=monadial%2Fphp-duration)Library[Utility &amp; Helpers](/categories/utility)

tmihalicka/php-duration
=======================

PHP Duration Type

1.0(2y ago)12.5kAGPL-3.0-onlyPHPPHP &gt;=8.1CI failing

Since Dec 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/monadial/php-duration)[ Packagist](https://packagist.org/packages/tmihalicka/php-duration)[ Docs](https://github.com/monadial/php-duration)[ RSS](/packages/tmihalicka-php-duration/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (4)Dependencies (13)Versions (9)Used By (0)

php-duration
============

[](#php-duration)

Missing PHP TimeUnit and Duration library

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

[](#installation)

```
composer require monadial/php-duration
```

Finite Duration
---------------

[](#finite-duration)

The FiniteDuration class is a representation of a finite duration of time. It provides functionality to perform operations and conversions on durations, such as addition, subtraction, multiplication, division, and conversion to different units of time.

### Factory Methods

[](#factory-methods)

- `fromTimeUnit(int $length, TimeUnit $unit): FiniteDuration`: Creates a new instance of the `FiniteDuration` class from the specified length and time unit.

    ```
    \Monadial\Duration\FiniteDuration::fromTimeUnit(1, TimeUnit::SECONDS); // create 1 second duration
    ```
- `fromNanos(int $nanos): FiniteDuration`: Creates a new instance of the `FiniteDuration` class from the specified duration in nanoseconds.

    ```
    \Monadial\Duration\FiniteDuration::fromNanos(1000); // create 1000 nanoseconds duration
    ```
- `fromString(string $duration): FiniteDuration`: Creates a new instance of the `FiniteDuration` class from a string representation of the duration.

    ```
    \Monadial\Duration\FiniteDuration::fromTimeUnit('1 minutes'); // create 1 minute duration
    ```

### Duration Conversion Methods

[](#duration-conversion-methods)

- `toNanos(): int`: Converts the duration to nanoseconds.
- `toMicros(): int`: Converts the duration to microseconds.
- `toMillis(): int`: Converts the duration to milliseconds.
- `toSeconds(): int`: Converts the duration to seconds.
- `toMinutes(): int`: Converts the duration to minutes.
- `toHours(): int`: Converts the duration to hours.
- `toDays(): int`: Converts the duration to days.
- `toUnit(TimeUnit $unit): float`: Converts the duration to the specified time unit.

### Arithmetic Operations

[](#arithmetic-operations)

- `add(Duration $other): FiniteDuration`: Adds another duration to the current duration.
- `subtract(Duration $other): FiniteDuration`: Subtracts another duration from the current duration.
- `multiply(int $factor): FiniteDuration`: Multiplies the duration by a factor.
- `division(int $divisor): FiniteDuration`: Divides the duration by a divisor.

### Other Methods

[](#other-methods)

- `isFinite(): bool`: Checks if the duration is finite.
- `equals(Duration $other): bool`: Checks if the current duration is equal to another duration.
- `toCoarsest(): Duration`: Converts the duration to the coarsest possible unit.
- `asDateTime(): DateTimeImmutable`: Converts the duration to a `DateTimeImmutable` object.

### Exceptions

[](#exceptions)

The `FiniteDuration` class may throw the following exceptions:

- `FiniteDurationBoundary`: Thrown when the duration exceeds the maximum or minimum value allowed by the time unit.
- `NanosecondsAreNotConvertibleToDateTime`: Thrown when attempting to convert a duration in nanoseconds to a `DateTimeImmutable` object (nanoseconds cannot be represented as a valid date and time).
- `UnableToConvertToDateTime`: Thrown when the duration cannot be converted to a `DateTimeImmutable` object due to limitations or errors.

Please note that this is just an overview of the `FiniteDuration` class and its available methods. For detailed information on each method and its usage, refer to the class implementation and documentation.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

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

Total

5

Last Release

1053d ago

Major Versions

0.4 → 1.02023-06-29

PHP version history (4 changes)0.1PHP ^7.4

0.2PHP ^7.4 || ^8.0

0.4PHP ^7.4|~8

1.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/9887dfedce25e561429934003d89e119611ad26f2cfa4fc65ee1f7914a6d2ca3?d=identicon)[tmihalicka](/maintainers/tmihalicka)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tmihalicka-php-duration/health.svg)

```
[![Health](https://phpackages.com/badges/tmihalicka-php-duration/health.svg)](https://phpackages.com/packages/tmihalicka-php-duration)
```

PHPackages © 2026

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