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

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

stevegrunwell/time-constants
============================

A series of constants designed to make it easier to express time in PHP applications

v2.0.2(1y ago)28402.4k—0.2%82MITPHPPHP ^7.0 | ^8.0

Since Mar 21Pushed 1y ago2 watchersCompare

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

READMEChangelog (8)Dependencies (4)Versions (10)Used By (2)

Time Constants
==============

[](#time-constants)

[![Unit Tests](https://github.com/stevegrunwell/time-constants/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/stevegrunwell/time-constants/actions/workflows/unit-tests.yml)[![Packagist](https://camo.githubusercontent.com/78c78b71177e859af884acb3fb658d86c7c5a88b219b75965d22629ccba8184c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746576656772756e77656c6c2f74696d652d636f6e7374616e74732e737667)](https://packagist.org/packages/stevegrunwell/time-constants)

The Time Constants package defines a number of useful PHP constants within your application, making it easier to express measures of time.

For example, assume we have a `cache()` function that accepts three arguments:

1. The cache key.
2. The value to cache.
3. The amount of time (in seconds) to cache the value.

Currently, caching a value for 24 hours might look something like this:

```
cache($cacheKey, $value, 24 * 60 * 60);
```

Instead of spending the time figuring out what `24 * 60 * 60` means (or the fact that `86400` is meant to be one day in seconds), **Time Constants** allows you to represent the time using an easy-to-understand PHP constant:

```
cache($cacheKey, $value, \TimeConstants\DAY_IN_SECONDS);
```

If the requirements changed and we needed to cache the value for multiple days, we can rewrite it as:

```
cache($cacheKey, $value, 5 * \TimeConstants\DAY_IN_SECONDS);
```

These constants may seem familiar to WordPress developers, as they're absolutely [inspired by WordPress' use of time constants](https://codex.wordpress.org/Easier_Expression_of_Time_Constants). This package goes a bit further, however, adding `*_IN_MINUTES` constants, for easier use with libraries like [Laravel's `Cache` facade](https://laravel.com/docs/master/cache#cache-usage).

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

[](#installation)

Time Constants is intended to be installed via Composer:

```
$ composer require stevegrunwell/time-constants
```

The package has been configured to automatically expose the `constants.php` file via the Composer-generated autoloader, so you'll be ready to use the constants as soon as the package has been installed!

Defined constants
-----------------

[](#defined-constants)

This is a list of all constants defined by this package, along with their values. Each constant is wrapped in a `if (! defined(...))` conditional, ensuring these constants can easily be redefined if necessary and won't conflict with existing constants.

As of version 2.0.0 of this library, all of these constants are defined in the `TimeConstants` namespace. If you are upgrading from version 1.x, [please see the 2.0.0 release notes for notes about migration](https://github.com/stevegrunwell/time-constants/releases/tag/v2.0.0).

> Please note that these constants are defined for convenience, and not necessarily for accuracy; all months are treated as 30 days, and years as 365 days. If you need support for leap years or more advanced measures of time, you might consider [PHP's `DateTime` class](http://php.net/manual/en/book.datetime.php) or [Nesbot's Carbon package](https://carbon.nesbot.com/docs/).

### Time based in seconds

[](#time-based-in-seconds)

- `ONE_SECOND` (1 second)
- `MINUTE_IN_SECONDS` (60 seconds)
- `HOUR_IN_SECONDS` (3600 seconds)
- `DAY_IN_SECONDS` (86,400 seconds)
- `WEEK_IN_SECONDS` (604,800 seconds)
- `MONTH_IN_SECONDS` (2,592,000 seconds)
- `YEAR_IN_SECONDS` (31,536,000 seconds)

### Time based in minutes

[](#time-based-in-minutes)

- `ONE_MINUTE` (1 minute)
- `HOUR_IN_MINUTES` (60 minutes)
- `DAY_IN_MINUTES` (1,440 minutes)
- `WEEK_IN_MINUTES` (10,080 minutes)
- `MONTH_IN_MINUTES` (43,200 minutes)
- `YEAR_IN_MINUTES` (525,600 minutes)

### Multipliers

[](#multipliers)

These can be helpful when dealing with fractions of a second. For example, all of the following are equivalent:

```
6000 === (6 * ONE_SECOND) * 1000 === 6 * MILLISECONDS_PER_SECOND
```

- `MILLISECONDS_PER_SECOND` (1,000ms/s)
- `MICROSECONDS_PER_SECOND` (1,000,000µs/s)
- `NANOSECONDS_PER_SECOND` (1,000,000,000ns/s)
- `PICOSECONDS_PER_SECOND` (1,000,000,000,000ps/s)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 98.9% 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 ~335 days

Recently: every ~236 days

Total

8

Last Release

633d ago

Major Versions

v1.2.0 → v2.0.02024-08-20

PHP version history (2 changes)v1.1.1PHP ^7.0

v1.1.2PHP ^7.0 | ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/05f4d610f0de13ac1c23825f691fd05f2dd37ae9e8f0483e2dc4f1ca1e2bfb32?d=identicon)[stevegrunwell](/maintainers/stevegrunwell)

---

Top Contributors

[![stevegrunwell](https://avatars.githubusercontent.com/u/233836?v=4)](https://github.com/stevegrunwell "stevegrunwell (87 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

---

Tags

composer-packageconstantsphptime

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

PHPackages © 2026

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