2017 © Pedro Peláez
 

library iso_duration_converter

Easily convert ISO_8601 Duration time format to seconds and convert seconds to ISO-8601 Duration

image

bretterer/iso_duration_converter

Easily convert ISO_8601 Duration time format to seconds and convert seconds to ISO-8601 Duration

  • Thursday, February 11, 2016
  • by bretterer
  • Repository
  • 0 Watchers
  • 18 Stars
  • 7,060 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 10 % Grown

The README.md

PHP ISO8601 Duration Converter

Easily converts ISO 8601 Durations to Seconds and Seconds to ISO 8601 Durations, (*1)

Installation

composer require bretterer/iso_duration_converter

Usage

$converter = new \Bretterer\IsoDurationConverter\DurationParser();
$converter->parse('PT8S'); // Returns 8
$converter->parse('PT5M'); // Returns 300
$converter->parse('PT20H'); // Returns 72000
$converter->parse('PT6M4S'); // Returns 364

$converter->compose(8); // Returns PT8S
$converter->compose(300); // Returns PT5M
$converter->compose(7200); // Returns PT20H
$converter->compose(364); //Returns PT6M4S

$converter->parse('P5W'); // Returns 3024000
// To Returns Weeks, The second argument should be true
$converter->compose(3024000, true); // Returns P5W
$converter->compose(3024000); // Returns P35D

$converter->parse('Hello World'); // Throws 'Invalid Argument Exception' with Message 'Invalid Duration'
$converter->parse('P10Y10M10D'); // Throws 'Invalid Argument Exception' with Message 'Ambiguous Duration'

Years and Months

If years are passed into the parse method, an invalid argument exception will be thrown., (*2)

If you are wanting to convert seconds into months, pass true as the second argument in the compose method, (*3)

License

MIT, (*4)

The Versions

11/02 2016

dev-master

9999999-dev

Easily convert ISO_8601 Duration time format to seconds and convert seconds to ISO-8601 Duration

  Sources   Download

MIT

11/02 2016

v0.1.0

0.1.0.0

Easily convert ISO_8601 Duration time format to seconds and convert seconds to ISO-8601 Duration

  Sources   Download

MIT