symandy/duration

PHP class for durations

v2.0.0 2023-04-30 17:43 UTC

This package is auto-updated.

Last update: 2024-10-30 01:33:17 UTC


README

Actions Status Type Coverage

Symandy Duration

PHP package to represent durations

Installation

  • Add package to your project using composer

    $ composer require symandy/duration

Usage

  • Instantiate Symandy\Component\Duration\Duration class
use Symandy\Component\Duration\Duration;

$duration = new Duration('4 minutes 40 seconds');
$duration = new Duration('4m 40s');
  • Display at any format
use Symandy\Component\Duration\Duration;

$duration = new Duration('4 minutes 40 seconds');

echo $duration->format(); // Default : 0:04:40
echo $duration->format('%h:%m:%s'); // 0:04:40
echo $duration->format('%mm%ss'); // 4m 40s
  • Add duration changes
use Symandy\Component\Duration\Duration;

$duration = new Duration('4 minutes 40 seconds');
$duration->addMinutes(10);

echo $duration->format('%mm%ss'); // 14m 40s