joanfabregat / iso8601-to-seconds
Converts ISO 8601 duration to seconds
Package info
github.com/joanfabregat/iso8601-to-seconds
pkg:composer/joanfabregat/iso8601-to-seconds
v2.0
2026-04-15 18:58 UTC
Requires
- php: >=8.2
Requires (Dev)
- phpunit/phpunit: ^11.5.50
This package is auto-updated.
Last update: 2026-04-15 18:59:15 UTC
README
A simple PHP library to convert ISO 8601 durations to seconds.
Accepts both ISO 8601 duration strings (e.g. PT1H30M) and DateInterval objects.
Requirements
- PHP >= 8.2
Installation
composer require joanfabregat/iso8601-to-seconds
Usage
use JoanFabregat\Iso8601ToSeconds\Iso8601ToSeconds; // From an ISO 8601 string $seconds = Iso8601ToSeconds::convert('PT1H'); echo $seconds; // 3600 // From a DateInterval object $interval = new DateInterval('PT1H'); $seconds = Iso8601ToSeconds::convert($interval); echo $seconds; // 3600 // Combined durations $seconds = Iso8601ToSeconds::convert('P1DT2H30M15S'); echo $seconds; // 95415 // Invalid input throws \InvalidArgumentException Iso8601ToSeconds::convert('not a duration'); // throws InvalidArgumentException
License
This library is published under the MIT license (see LICENSE).