Spork Code Libraries

TimeElapsed

View helper to render a DateTime object as the amount of time elapsed since the DateTime. The precision of the elapsed time can be specified when the helper is invoked.

Extends
\Zend\Form\View\Helper\AbstractHelper

Constants

PRECISION_SECONDS

PRECISION_SECONDS

PRECISION_MINUTES

PRECISION_MINUTES

PRECISION_HOURS

PRECISION_HOURS

PRECISION_DAYS

PRECISION_DAYS

Methods

__invoke()

__invoke(\DateTimeInterface  $datetime, string  $precision = self::PRECISION_SECONDS, integer  $range = 4) : string

Render a DateTime object as the elapsed time since the DateTime.

The precision of the elapsed time can be specified in two ways. The second parameter sets the minimum precision to days, hours, minutes or seconds (default).

$timeElapsed($datetime, 'hour'); Renders the number of days and hours since $datetime, but ignores minutes and seconds.

The third parameter sets the number of levels of precision that are rendered.

$timeElapased($datetime, 'second', 2); If the elapsed time is greater than 1 day it will render the number of days and hours. If it less than 1 day but greater than 1 hour it will render the number of hours and minutes.

Parameters

\DateTimeInterface $datetime
string $precision

Minimum precision 'day' | 'hour' | 'minute' | 'second'

integer $range

Precision range

Returns

string