joanfabregat / iso8601-to-seconds
Converts ISO 8601 duration to seconds
v1.0
2024-04-30 10:23 UTC
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^11
README
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).