{"id":31774166,"url":"https://github.com/ajimoti/cache-duration","last_synced_at":"2025-10-10T04:49:10.375Z","repository":{"id":41860251,"uuid":"449831864","full_name":"ajimoti/cache-duration","owner":"ajimoti","description":"A readable and fluent way to generate PHP cache time.","archived":false,"fork":false,"pushed_at":"2023-10-10T00:00:03.000Z","size":60,"stargazers_count":25,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-27T17:33:36.711Z","etag":null,"topics":["cache","cache-duration","laravel-cache","php","php-cache","symfony-cache"],"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/ajimoti.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null},"funding":{"github":"ajimoti"}},"created_at":"2022-01-19T19:41:45.000Z","updated_at":"2025-06-16T11:11:31.000Z","dependencies_parsed_at":"2023-02-16T12:31:57.836Z","dependency_job_id":null,"html_url":"https://github.com/ajimoti/cache-duration","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"spatie/package-skeleton-php","purl":"pkg:github/ajimoti/cache-duration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimoti%2Fcache-duration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimoti%2Fcache-duration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimoti%2Fcache-duration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimoti%2Fcache-duration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajimoti","download_url":"https://codeload.github.com/ajimoti/cache-duration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajimoti%2Fcache-duration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002656,"owners_count":26083442,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cache","cache-duration","laravel-cache","php","php-cache","symfony-cache"],"created_at":"2025-10-10T04:49:07.342Z","updated_at":"2025-10-10T04:49:10.364Z","avatar_url":"https://github.com/ajimoti.png","language":"PHP","readme":"# PHP Cache Duration\n![Banner](https://banners.beyondco.de/Cache%20Duration%20Package.png?theme=dark\u0026packageManager=composer+require\u0026packageName=ajimoti%2Fcache-duration\u0026pattern=charlieBrown\u0026style=style_1\u0026description=A+more+readable+way+to+get+time+in+seconds+while+caching\u0026md=1\u0026showWatermark=1\u0026fontSize=100px\u0026images=clock)\n\n## Introduction\nA readable and fluent way to generate PHP cache time.\n\nBuilt and written by [Ajimoti Ibukun](https://www.linkedin.com/in/ibukun-ajimoti-3420a786/)\n\n## Quick Samples\nInstead of this:\n```php\n$cacheDuration = 25 * 60 * 60; // twenty five hours\nRedis::expire($userData, $cacheDuration);\n```\n\nYou can do this\n```php\n$cacheDuration = Duration::twentyFiveHours(); // returns 25 hours in seconds (25 * 60 * 60)\nRedis::expire($userData, $cacheDuration);\n\n// or\n$cacheDuration = Duration::hours(25); // returns 25 hours in seconds (25 * 60 * 60)\nRedis::expire($userData, $cacheDuration);\n```\n\nYou can also do this:\n```php\n$cacheDuration = Duration::at('first day of January 2023'); // returns the time difference between the present time and the first of january 2023 in seconds\n\nRedis::expire($userData, $cacheDuration);\n```\n\n## Requirements\n- PHP 8.0 or higher\n\n## Installation\nYou can install the package via composer:\n```bash\ncomposer require ajimoti/cache-duration --with-all-dependencies\n```\n\n## Documentation\nAfter installing the package via composer, import the `Duration` trait inside your class, then you are set.\n```php\n\u003c?php\nrequire 'vendor/autoload.php';\n\nuse Ajimoti\\CacheDuration\\Duration;\n\nvar_dump(Duration::fourtyMinutes()); // returns 2400;\nvar_dump(Duration::tenHours()); // returns 36000;\nvar_dump(Duration::fiftyFourDays()); // returns 4665600;\n```\n\n### Available methods\n| Method      | Expectations | \n| ----------- | ----------- |\n| [seconds($value)](#secondsvalue)  | Expects time in seconds  |\n| [minutes($value)](#minutesvalue)   | Expects time in minutes  |\n| [hours($value)](#hoursvalue)  | Expects time in hours  |\n| [days($value)](#daysvalue) | Expects time in days  |\n| [at($value)](#atvalue)  | Expects `string`, `carbon` instance, or `DateTime` instance  |\n\n### Dynamic calls\nIn addition to the methods provided above, the package uses `PHP` `__callStatic()` method to allow you make dynamic calls on the `Duration` trait.\n\nFor example, you want to get the number of seconds in 37 days, you can achieve this by calling a `camel-case` text of the number (`thirtySeven` in this case), plus the unit (`Days` in this case). That will leave us with something like this:\n\n```php\n// The formula = camelCaseOfTheNumberInWords + Unit\nDuration::thirtySevenDays(); // returns the number of seconds in 37 days\n```\n\n\u003e **Note:** The number in words **MUST** be in `camel-case`. Any other case will throw an `InvalidArgumentException`. Additionally, it must be followed by a `title-case` of the unit. The available units are `Seconds`, `Minutes`, `Hours`, and `Days`.\n\n\n## Usage\n### `seconds($value)`\nGet time in seconds. It basically returns the same value passed into it.\n```php\nuse Ajimoti\\CacheDuration\\Duration;\n\n$cacheDuration = Duration::seconds(30); // returns 30\n\n// or dynamically\n$cacheDuration = Duration::thirtySeconds(); // returns 30\n```\n\n### `minutes($value)`\nConverts time in minutes into seconds.\n```php\nuse Ajimoti\\CacheDuration\\Duration;\n\n$cacheDuration = Duration::minutes(55); // returns 55 minutes in seconds (55 * 60)\n\n// or dynamically\n$cacheDuration = Duration::fiftyFiveMinutes(); // returns 55 minutes in seconds (55 * 60)\n```\n\n### `hours($value)`\nConverts time in hours into seconds.\n```php\nuse Ajimoti\\CacheDuration\\Duration;\n\n$cacheDuration = Duration::hours(7); // returns 7 hours in seconds (7 * 60 * 60)\n\n// or dynamically\n$cacheDuration = Duration::sevenHours(); // returns 7 hours in seconds (7 * 60 * 60)\n```\n\n### `days($value)`\nConverts time in days into seconds.\n```php\nuse Ajimoti\\CacheDuration\\Duration;\n\n$cacheDuration = Duration::days(22); // returns 22 days in seconds (22 * 24 * 60 * 60)\n\n// or dynamically\n$cacheDuration = Duration::twentyTwoDays(); // returns 22 days in seconds (22 * 24 * 60 * 60)\n```\n\n### `at($value)`\nThis method allows you to convert a `Carbon\\Carbon` instance, `DateTime` instance or  `string` of date into seconds. \n\nIt returns the difference in seconds between the argument passed and the current `timestamp`.\n\n\u003e The date passed into this method **MUST** be a date in the future. When a string is passed, the text **MUST** be compatible with `Carbon::parse()` method, else an exception will be thrown\n\n#### Examples\n```php\nuse Date;\nuse Carbon\\Carbon;\nuse Ajimoti\\CacheDuration\\Duration;\n\n// Carbon instance\n$cacheDuration = Duration::at(Carbon::now()-\u003eaddMonths(3)); // returns time in seconds between the present timestamp and three months time\n\n// Datetime instance\n$cacheDuration = Duration::at(new DateTime('2039-09-30')); // returns time in seconds between the present timestamp and the date passed (2039-09-30).\n\n// String\n$cacheDuration = Duration::at('first day of January 2023'); // returns time in seconds between the present timestamp and the first of January 2023.\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [ajimoti](https://github.com/ajimoti)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":["https://github.com/sponsors/ajimoti"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajimoti%2Fcache-duration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajimoti%2Fcache-duration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajimoti%2Fcache-duration/lists"}