herrera-io/date-interval
Extends PHP’s DateInterval with handy conversions: turn intervals into ISO interval specs and seconds, and recreate intervals from seconds. Useful for normalizing and serializing durations (e.g., P2H <-> 7200).
Provides additional functionality to the DateInterval class.
The DateInterval class builds on the existing DateInterval class provided by PHP. With the new class, you may
DateInterval to the interval specDateInterval to the number of seconds
DateInterval from the number of secondsThe conversion to seconds requires a bit of explaining.
Add it to your list of Composer dependencies:
$ composer require herrera-io/date-interval=1.*
<?php
use Herrera\DateInterval\DateInterval;
$interval = new DateInteval('P2H');
echo $interval->toSeconds(); // "7200"
echo DateInterval::toSeconds($interval); // "7200"
echo $interval->toSpec(); // "P2H"
echo DateInterval::toSpec($interval); // "P2H"
How can I help you explore Laravel packages today?