PHPackages                             lexide/chronos - 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. lexide/chronos

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

lexide/chronos
==============

Provides classes that return timestamps

v2.2.0(2y ago)07.8k↑50%MITPHPPHP &gt;=8.0

Since Feb 5Pushed 2y ago1 watchersCompare

[ Source](https://github.com/lexide/chronos)[ Packagist](https://packagist.org/packages/lexide/chronos)[ Docs](https://github.com/lexide/chronos)[ RSS](/packages/lexide-chronos/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (3)Versions (15)Used By (0)

Chronos
=======

[](#chronos)

Chronos provides classes that return timestamps in order to abstract dependencies on system time. Mostly this is useful when unit testing code, as you are able to mock the `TimeProviderInterface` and not rely on calls to get system time

It also has a stopwatch, which uses the time providers to generate durations in seconds

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

[](#installation)

```
composer require lexide/chronos

```

To use the `lexide/syringe` DI config supplied with this library, add the following to your composer.json

```
"extra": {
    "lexide/puzzle-di": {
        "whitelist": {
            "lexide/syringe": [
                "lexide/chronos"
            ]
        }
    }
}
```

*NOTE: you will need to install lexide/puzzle-di in your project to take advantage of this feature*

TimeProviders
-------------

[](#timeproviders)

The TimeProviders included in this library all return the number of seconds from a given point-in-time. Each class has a `get` method which is used to get the current time. When mocking these classes, you can set an expectation on this method to return values that simulate a period of time having elapsed.

There are a number of Provider classes supplied in this library:

- `TimeProvider` - returns a unix timestamp in seconds
- `MilliTimeProvider`- returns a unix timestamp with millisecond precision
- `MicroTimeProvider`- returns a unix timestamp with microsecond precision
- `NanoTimeProvider` returns an arbitrary timestamp with nanosecond precision

*NOTE: The `NanoTimeProvider` **does not** return a unix timestamp. It is based on the `hrtime` function which returns nanoseconds elapsed from an arbitrary point-in-time, such as system start time. As this point-in-time cannot be known beforehand, `NanoTimeProvider` cannot be used for date calculations, only for timing durations*

### Custom TimeProviders

[](#custom-timeproviders)

If you need to use a different unit of time, such as an integer of milliseconds, you can create a new class that implements `Lexide\Chronos\TimeProvider\TimeProviderInterface`. In its `get` method, you can return any integer or float value that meets your requirements.

TimeSkippers
------------

[](#timeskippers)

TimeSkippers delay PHP from processing a script, using `sleep()` and related functions. Each class has a `skip` method which requires an argument representing the number of seconds to delay by. Note that this value is *always* the number of seconds; passing `100` to the `MicroTimeSkipper` will delay by 100 seconds, *not* 100 microseconds

The Skipper classes available in this library are:

- `TimeSkipper` - delay's processing by whole second increments
- `MilliTimeProvider`- delay's processing by millisecond increments
- `MicroTimeProvider`- delay's processing by microsecond increments
- `NanoTimeProvider` delay's processing by nanosecond increments

Stopwatches
-----------

[](#stopwatches)

The `StopWatch` classes perform the common function of timing the duration of a task. They use TimeProviders to capture a starting point-in-time and work out the difference between the start and a second point-in-time, when requested

### StopWatch class

[](#stopwatch-class)

To use a `StopWatch`, you must call `start()` on it to capture the starting time. Then you can call `stop()` to stop timing and return the time difference. Alternatively, if you want to continue timing, a call to `duration()` will return the time elapsed but keep the watch running, allowing `duration()` to be called multiple times.

### MultiStopWatch

[](#multistopwatch)

The `MultiStopWatch` is useful in situations where you want to record several concurrent durations without having a `StopWatch` for each one. The functionality is the same as for `StopWatch` but in each case, a `key` argument is used to separate concurrent timings.

For example, calling `start("foo")` and then `start("bar")` will start two timers. If you then call `stop("foo")` the timer for "bar" will continue to run until `stop` is called with that key

### StopWatch modes

[](#stopwatch-modes)

Both StopWatches can operate in continuous or interval modes, which affect the value returned from calls to `duration()`

In continuous mode, `duration()` will return the difference between the current time and the initial start time, so measuring the total time since the timer was started.

Interval mode differs by setting the start time to the current time for each call to `duration()`. This allows measurement of the intervals between `duration()` calls; equivalent to individual lap times when using a real stopwatch

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 95.2% 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 ~128 days

Recently: every ~223 days

Total

8

Last Release

1033d ago

Major Versions

v1.0.0 → v2.0.02021-02-05

v1.0.1 → v2.0.12021-02-05

v1.1.0 → v2.1.12021-02-09

PHP version history (2 changes)v1.0.0PHP &gt;=5.3

v2.0.0PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

[![Danny-Smart](https://avatars.githubusercontent.com/u/113538899?v=4)](https://github.com/Danny-Smart "Danny-Smart (20 commits)")[![downsider](https://avatars.githubusercontent.com/u/4508388?v=4)](https://github.com/downsider "downsider (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lexide-chronos/health.svg)

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

PHPackages © 2026

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