joanfabregat/iso8601-to-seconds

Converts ISO 8601 duration to seconds

v1.0 2024-04-30 10:23 UTC

This package is auto-updated.

Last update: 2024-04-30 10:24:44 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

A simple package to convert ISO 8601 duration to seconds

Installation

The package is available on Packagist. The recommended way to install the library is through Composer:

composer require joanfabregat/iso8601-to-seconds

Usage

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');

License

The library is published under the MIT license (see LICENSE file).