A simple package to convert ISO 8601 duration to seconds
The package is available on Packagist. The recommended way to install the library is through Composer:
composer require joanfabregat/iso8601-to-seconds
use JoanFabregat\Iso8601ToSeconds\Iso8601ToSeconds;
$seconds = Iso8601ToSeconds::convert('PT1H');
echo $token; // will echo 3600
$interval = new DateInterval('PT1H');
$seconds = Iso8601ToSeconds::convert($interval);
echo $token; // will echo 3600
$interval = DateInterval::createFromDateString('1 hour');
$seconds = Iso8601ToSeconds::convert($interval);
echo $token; // will echo 3600
// will throw an \InvalidArgumentException exception
$token = Iso8601ToSeconds::convert('a random string');
The library is published under the MIT license (see LICENSE
file).