2017 © Pedro Peláez
 

library php-duration

Converts between colon formatted time, human-readable time and seconds

image

khill/php-duration

Converts between colon formatted time, human-readable time and seconds

  • Thursday, July 5, 2018
  • by kevinkhill
  • Repository
  • 4 Watchers
  • 67 Stars
  • 93,082 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 10 Forks
  • 0 Open issues
  • 8 Versions
  • 5 % Grown

The README.md

PHP-Duration

Convert durations between colon formatted time, human-readable time and seconds

Total Downloads License Minimum PHP Version PayPal, (*1)

Current Release Build Status Coverage Status, (*2)

This package was created with a very specific goal in mind, to enable an easy way for users to input how long something took, as a duration of time., (*3)

The library can accept either in colon separated format, like 2:43 for 2 minutes and 43 seconds OR written as human readable or abbreviated time, such as 6m21s for 6 minutes and 21 seconds., (*4)

Both can be converted into seconds and minutes with precision for easy storage into a database., (*5)

Seconds, colon separated, abbreviated, all three can be parsed and interchanged. - supports hours, minutes, and seconds (with microseconds) - humanized input supports any form of the words "hour", "minute", "seconds" - Example, you could input 1h4m2s or 4 Hr. 32 Min., (*6)

Install

composer require khill/php-duration:~1.0

Usage

use Khill\Duration\Duration;


$duration = new Duration('7:31');

echo $duration->humanize();  // 7m 31s
echo $duration->formatted(); // 7:31
echo $duration->toSeconds(); // 451
echo $duration->toMinutes(); // 7.5166
echo $duration->toMinutes(null, 0); // 8
echo $duration->toMinutes(null, 2); // 7.52
$duration = new Duration('1h 2m 5s');

echo $duration->humanize();  // 1h 2m 5s
echo $duration->formatted(); // 1:02:05
echo $duration->toSeconds(); // 3725
echo $duration->toMinutes(); // 62.0833
echo $duration->toMinutes(null, 0); // 62
// Configured for 6 hours per day
$duration = new Duration('1.5d 1.5h 2m 5s', 6);

echo $duration->humanize();  // 1d 4h 32m 5s
echo $duration->formatted(); // 10:32:05
echo $duration->toSeconds(); // 37925
echo $duration->toMinutes(); // 632.083333333
echo $duration->toMinutes(null, 0); // 632
$duration = new Duration('4293');

echo $duration->humanize();  // 1h 11m 33s
echo $duration->formatted(); // 1:11:33
echo $duration->toSeconds(); // 4293
echo $duration->toMinutes(); // 71.55
echo $duration->toMinutes(null, 0); // 72

Note

You do not have to create a new object for each conversion, you can also pass any of the three forms into any of the methods to get the immediate output., (*7)

$duration = new Duration;

echo $duration->humanize('1h 2m 5s');  // 1h 2m 5s
echo $duration->formatted('1h 2m 5s'); // 1:02:05
echo $duration->toSeconds('1h 2m 5s'); // 3725
echo $duration->toMinutes('1h 2m 5s'); // 62.0833
echo $duration->toMinutes('1h 2m 5s', true); // 62

The Versions

05/07 2018

dev-master

9999999-dev

Converts between colon formatted time, human-readable time and seconds

  Sources   Download

MIT

The Development Requires

time convert duration seconds

05/07 2018

1.0.6

1.0.6.0

Converts between colon formatted time, human-readable time and seconds

  Sources   Download

MIT

The Development Requires

time convert duration seconds

07/04 2018

1.0.5

1.0.5.0

Converts between colon formatted time, human-readable time and seconds

  Sources   Download

MIT

The Development Requires

time convert duration seconds

09/09 2017

1.0.4

1.0.4.0

Converts between colon formatted time, human-readable time and seconds

  Sources   Download

MIT

The Development Requires

time convert duration seconds

10/09 2016

1.0.3

1.0.3.0

Converts between colon formatted time, human-readable time and seconds

  Sources   Download

MIT

The Development Requires

time convert duration seconds

05/04 2016

1.0.2

1.0.2.0

Converts between colon formatted time, human-readable time and seconds

  Sources   Download

MIT

The Development Requires

time convert duration seconds

21/03 2016

1.0.1

1.0.1.0

Converts between colon formatted time, human-readable time and seconds

  Sources   Download

MIT

The Development Requires

17/03 2015

1.0.0

1.0.0.0

Converts between colon formatted time, human-readable time and seconds

  Sources   Download

MIT

The Development Requires