2017 © Pedro Peláez
 

yii2-extension yii2-helper-time

A useful helper function for time calculations - especially for durations - for Yii Framework 2

image

juniq/yii2-helper-time

A useful helper function for time calculations - especially for durations - for Yii Framework 2

  • Monday, April 17, 2017
  • by juniq
  • Repository
  • 1 Watchers
  • 3 Stars
  • 303 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 3 Versions
  • 9 % Grown

The README.md

yii2-helper-time

Description

A useful helper function for time calculations - especially for durations - for Yii Framework 2. You can use the function Time::formatDuration to convert seconds into human readable duration strings like: 5 days 8 hours 19 minutes 11 seconds, (*1)

How to install

Composer

The easiest way to install this package is to use composer. If you don't have composer get it here:, (*2)

https://getcomposer.org/download/, (*3)

Now you can run the following commands in your root project directory:, (*4)

composer require "juniq/yii2-helper-time" "*"

or (depending on your installation type), (*5)

php composer.phar require "juniq/yii2-helper-time" "*"

Manually download

Download the latest version here:, (*6)

https://github.com/juniq/yii2-helper-time/, (*7)

How to use it

To convert seconds into human readable duration strings, you can use the following function:, (*8)

Time::formatDuration($time, $length = 'short', $custom_units = false, $separator = ', ')
Parameter Type Required? Description
$time Integer yes The time in seconds you want to format.
$length String optional The display lenghts. Use "short" or "long".
$custom_units Array/Boolean optional Time units to display. Pass "false" to use all time units. Possible values: y, m, w, d, h, i, s.
$separator String optional The separator sign between time units.

Examples

use juniq\helper\Time;

$time_in_seconds = 5781; // 1 hour 36 minutes, 21 seconds

echo Time::formatDuration($time_in_seconds);
// ouput: 1 hour 36 minutes, 21 seconds

echo Time::formatDuration($time_in_seconds, 'long', ['h','i','s'], 'long');
// ouput: 1 hour 36 minutes 21 seconds

echo Time::formatDuration($time_in_seconds, 'short', ['h','i','s'], ',');
// output: 36 minutes, 21 seconds

echo Time::formatDuration($time_in_seconds, 'short',  ['i','s'], ',');
// output: 96 m, 21 s

License

Look at 'LICENSE.md' file, (*9)

Copyright by JUNIQ GmbH & Co. KG. Author: Richard Jung, (*10)

The Versions

17/04 2017

dev-master

9999999-dev https://github.com/juniq/yii2-helper-time

A useful helper function for time calculations - especially for durations - for Yii Framework 2

  Sources   Download

BSD-3-Clause

extension yii2 bootstrap helper yii time utilities duration

18/08 2015

1.1

1.1.0.0 https://github.com/juniq/yii2-helper-time

A useful helper function for time calculations - especially for durations - for Yii Framework 2

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 bootstrap helper yii time utilities duration

17/08 2015

1.0

1.0.0.0 https://github.com/juniq/yii2-helper-time

A useful helper function for time calculations - aspecially for durations - for Yii Framework 2

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 bootstrap helper yii time utilities duration