PHP time utilities for converting time values & creating time periods
You can install the package via composer:
composer require sfneal/time-helpers
Carbonate can be used to retrieve Carbon objects transformed from today's datetime. This is useful for getting a Carbon object that represents a datetime in the past or future.
use Sfneal\Helpers\Time\Carbonate;
// Retrieve a Carbon\Carbon object representing '3' days ago
$threeDaysAgo = Carbonate::daysAgo(3);
$threeDaysAgo = Carbonate::days(-3);
// Retrieve a Carbon\Carbon object representing '5' years ago
$fiveYearsAgo = Carbonate::yearsAgo(3);
$fiveYearsAgo = Carbonate::years(-3);
// Retrieve a Carbon\Carbon object representing '6' months ago
$sixMonthsAgo = Carbonate::monthsAgo(3);
$sixMonthsAgo = Carbonate::months(-3);
TimeConverter is used to convert between different units of time (hours, minutes & seconds).
use Sfneal\Helpers\Time\TimeConverter;
// Convert Hours to Minutes
$hours = 5.5;
$minutes = (new TimeConverter())->setHours($hours)->minutes();
>>> 19800
// Convert Seconds to Hours
$seconds = 37800;
$hours = (new TimeConverter())->setSeconds($hours)->hours();
>>> 10.5
TimePeriod is used to retrieve a start & end datetime for a period of time (like today, last month, etc). This can be useful when creating time scoped queries, like collecting all the orders from last month.
use Sfneal\Helpers\Time\TimePeriod;
// Retrieve a TimePeriod representing today (02/16/2021)
[$start, $end] = TimePeriods::today();
// $start >>> 2021-02-16 00:00:00
// $end >>> 2021-02-16 23:59:59
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email stephen.neal14@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the PHP Package Boilerplate.