2017 © Pedro Peláez
 

library readable-duration

Convert a value in seconds into a human-readable convenience duration

image

webignition/readable-duration

Convert a value in seconds into a human-readable convenience duration

  • Friday, March 16, 2018
  • by webignition
  • Repository
  • 2 Watchers
  • 5 Stars
  • 32,946 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

readable-duration

Ever wondered how long a value in seconds might be in units that your human brain can more comfortably understand?, (*1)

Now you can convert a value in seconds into a human-readable convenience duration!, (*2)

Features:, (*3)

  • Get the number of years, months, days, hours, minutes and seconds for a given value
  • Get a value in seconds in years, months, days, hours, minutes or seconds
  • Get a value in seconds as the most appropriate human-readable value

Get the number of years, months, days, hours, minutes and seconds for a given value

<?php
use webignition\ReadableDuration\Factory;

/**
 * 100000 seconds is 1 day, 3 hours, 46 minutes and 40 seconds
 */
$factory = new Factory();    
$readableDuration = $factory->create(100000);

$readableDuration->getDays();
// 1

$readableDuration->getHours();
// 3

$readableDuration->getMinutes();
// 46

$readableDuration->getSeconds();
// 40

Get a value in seconds in years, months, days, hours, minutes or seconds

<?php

use webignition\ReadableDuration\Factory;

/**
 * 100000 seconds as years, months, days, hours, minute or seconds
 *
 * Note: these are human-readable convenience representations not exact
 *
 * 100000 seconds is strictly 1.16 days. As far as convenience is concerned, that's 1 day.
 * 100000 seconds is strictly 27.78 hours. As far as convenience is concerned, that's 28 hours.
 */
$factory = new Factory();    
$readableDuration = $factory->create(100000);

$readableDuration->getInYears();
// 0

$readableDuration->getInMonths();
// 0

$readableDuration->getInDays();
// 1

$readableDuration->getInHours();
// 28

$readableDuration->getInMinutes();
// 1667

$readableDuration->getInSeconds();
// 100000

Get a value in seconds as the most appropriate human-readable value

<?php

use webignition\ReadableDuration\Factory;

/**
 * 100000 seconds:
 *
 * - represented as a single time unit is 1 day
 * - represented as two time units is 1 day 4 hours
 * - represented as three time units is 1 day 3 hours 47 minutes
 *
 */
$factory = new Factory();    
$readableDuration = $factory->create(100000);

/**
 * 100000 seconds, as a single time unit is 1 day
 */
$this->factory->getInMostAppropriateUnits($readableDuration);
// [
//     [
//         'unit' => 'day',
//         'value' => 1
//     ]
// ]


/**
 * 100000 seconds, as two time units is 1 day 4 hours
 */
$this->factory->getInMostAppropriateUnits($readableDuration, 2);
// [
//     [
//         'unit' => 'day',
//         'value' => 1
//     ],
//     [
//         'unit' => 'hour',
//         'value' => 4
//     ]
// ]

/**
 * 100000 seconds, as three time units is 1 day 3 hours 47 minutes
 */
$this->factory->getInMostAppropriateUnits($readableDuration, 3);
// [
//     [
//         'unit' => 'day',
//         'value' => 1
//     ],
//     [
//         'unit' => 'hour',
//         'value' => 3
//     ],
//     [
//         'unit' => 'minute',
//         'value' => 47
//     ]
// ]

The Versions

16/03 2018

dev-master

9999999-dev https://github.com/webignition/readable-duration

Convert a value in seconds into a human-readable convenience duration

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Jon Cram

time readable duration humand-readable

16/03 2018

0.3

0.3.0.0 https://github.com/webignition/readable-duration

Convert a value in seconds into a human-readable convenience duration

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Jon Cram

time readable duration humand-readable

16/03 2018

dev-cs-psr4

dev-cs-psr4 https://github.com/webignition/readable-duration

Convert a value in seconds into a human-readable convenience duration

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Jon Cram

time readable duration humand-readable

28/03 2013

0.2

0.2.0.0 https://github.com/webignition/readable-duration

Convert a value in seconds into a human-readable convenience duration

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jon Cram

time readable duration humand-readable

28/03 2013

0.1

0.1.0.0 https://github.com/webignition/readable-duration

Convert a value in seconds into a human-readable convenience duration

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Jon Cram

time readable duration humand-readable