Download the PHP package ajimoti/cache-duration without Composer
On this page you can find all versions of the php package ajimoti/cache-duration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ajimoti/cache-duration
More information about ajimoti/cache-duration
Files in ajimoti/cache-duration
Package cache-duration
Short Description This package provides a more readable way to get time in seconds while caching.
License MIT
Homepage https://github.com/ajimoti/cache-duration
Informations about the package cache-duration
PHP Cache Duration
Introduction
A readable and fluent way to generate PHP cache time.
Built and written by Ajimoti Ibukun
Quick Samples
Instead of this:
You can do this
You can also do this:
Requirements
- PHP 8.0 or higher
Installation
You can install the package via composer:
Documentation
After installing the package via composer, import the Duration
trait inside your class, then you are set.
Available methods
Method | Expectations |
---|---|
seconds($value) | Expects time in seconds |
minutes($value) | Expects time in minutes |
hours($value) | Expects time in hours |
days($value) | Expects time in days |
at($value) | Expects string , carbon instance, or DateTime instance |
Dynamic calls
In addition to the methods provided above, the package uses PHP
__callStatic()
method to allow you make dynamic calls on the Duration
trait.
For 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:
Note: The number in words MUST be in
camel-case
. Any other case will throw anInvalidArgumentException
. Additionally, it must be followed by atitle-case
of the unit. The available units areSeconds
,Minutes
,Hours
, andDays
.
Usage
seconds($value)
Get time in seconds. It basically returns the same value passed into it.
minutes($value)
Converts time in minutes into seconds.
hours($value)
Converts time in hours into seconds.
days($value)
Converts time in days into seconds.
at($value)
This method allows you to convert a Carbon\Carbon
instance, DateTime
instance or string
of date into seconds.
It returns the difference in seconds between the argument passed and the current timestamp
.
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
Examples
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- ajimoti
- All Contributors
License
The MIT License (MIT). Please see License File for more information.