{"id":16646885,"url":"https://github.com/stevegrunwell/time-constants","last_synced_at":"2025-05-01T00:51:09.708Z","repository":{"id":44878906,"uuid":"126208142","full_name":"stevegrunwell/time-constants","owner":"stevegrunwell","description":"A series of constants designed to make it easier to express time in PHP applications","archived":false,"fork":false,"pushed_at":"2024-08-23T18:34:21.000Z","size":119,"stargazers_count":27,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-04-14T07:06:03.425Z","etag":null,"topics":["composer-package","constants","php","time"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevegrunwell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-21T16:24:26.000Z","updated_at":"2024-08-23T18:34:25.000Z","dependencies_parsed_at":"2024-06-18T17:14:34.827Z","dependency_job_id":"daa3f6cd-8cc0-4b52-b236-ed54f77ced3f","html_url":"https://github.com/stevegrunwell/time-constants","commit_stats":{"total_commits":38,"total_committers":3,"mean_commits":"12.666666666666666","dds":"0.26315789473684215","last_synced_commit":"d8d1087f9961df56d7e221e433483943acbc127e"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevegrunwell%2Ftime-constants","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevegrunwell%2Ftime-constants/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevegrunwell%2Ftime-constants/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevegrunwell%2Ftime-constants/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevegrunwell","download_url":"https://codeload.github.com/stevegrunwell/time-constants/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251806170,"owners_count":21646841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer-package","constants","php","time"],"created_at":"2024-10-12T08:43:21.770Z","updated_at":"2025-05-01T00:51:09.688Z","avatar_url":"https://github.com/stevegrunwell.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Time Constants\n\n[![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)\n[![Packagist](https://img.shields.io/packagist/v/stevegrunwell/time-constants.svg)](https://packagist.org/packages/stevegrunwell/time-constants)\n\n\nThe Time Constants package defines a number of useful PHP constants within your application, making it easier to express measures of time.\n\nFor example, assume we have a `cache()` function that accepts three arguments:\n\n1. The cache key.\n2. The value to cache.\n3. The amount of time (in seconds) to cache the value.\n\nCurrently, caching a value for 24 hours might look something like this:\n\n```php\ncache($cacheKey, $value, 24 * 60 * 60);\n```\n\nInstead 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:\n\n```php\ncache($cacheKey, $value, \\TimeConstants\\DAY_IN_SECONDS);\n```\n\nIf the requirements changed and we needed to cache the value for multiple days, we can rewrite it as:\n\n```php\ncache($cacheKey, $value, 5 * \\TimeConstants\\DAY_IN_SECONDS);\n```\n\nThese 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).\n\n## Installation\n\nTime Constants is intended to be installed via Composer:\n\n```sh\n$ composer require stevegrunwell/time-constants\n```\n\nThe 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!\n\n## Defined constants\n\nThis 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.\n\nAs 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).\n\n\u003e 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/).\n\n### Time based in seconds\n\n* `ONE_SECOND` (1 second)\n* `MINUTE_IN_SECONDS` (60 seconds)\n* `HOUR_IN_SECONDS` (3600 seconds)\n* `DAY_IN_SECONDS` (86,400 seconds)\n* `WEEK_IN_SECONDS` (604,800 seconds)\n* `MONTH_IN_SECONDS` (2,592,000 seconds)\n* `YEAR_IN_SECONDS` (31,536,000 seconds)\n\n### Time based in minutes\n\n* `ONE_MINUTE` (1 minute)\n* `HOUR_IN_MINUTES` (60 minutes)\n* `DAY_IN_MINUTES` (1,440 minutes)\n* `WEEK_IN_MINUTES` (10,080 minutes)\n* `MONTH_IN_MINUTES` (43,200 minutes)\n* `YEAR_IN_MINUTES` (525,600 minutes)\n\n### Multipliers\n\nThese can be helpful when dealing with fractions of a second. For example, all of the following are equivalent:\n\n```php\n6000 === (6 * ONE_SECOND) * 1000 === 6 * MILLISECONDS_PER_SECOND\n```\n\n* `MILLISECONDS_PER_SECOND` (1,000ms/s)\n* `MICROSECONDS_PER_SECOND` (1,000,000µs/s)\n* `NANOSECONDS_PER_SECOND` (1,000,000,000ns/s)\n* `PICOSECONDS_PER_SECOND` (1,000,000,000,000ps/s)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevegrunwell%2Ftime-constants","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevegrunwell%2Ftime-constants","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevegrunwell%2Ftime-constants/lists"}