PHP Class Salavert\Twig\Extension\TimeAgoExtension

Inheritance: extends Twig_Extension
Show file Open project: salavert/time-ago-in-words Class Usage Examples

Protected Properties

Property Type Description
$translator Symfony\Component\Translation\TranslatorInterface

Public Methods

Method Description
__construct ( Symfony\Component\Translation\TranslatorInterface $translator ) Constructor method
distanceOfTimeInWordsFilter ( string | DateTime $from_time, string | DateTime $to_time = null, boolean $include_seconds = false, boolean $include_months = false ) : string Reports the approximate distance in time between two times given in seconds or in a valid ISO string like.
getFilters ( )
getName ( ) : string Returns the name of the extension.
timeAgoInWordsFilter ( $from_time, boolean $include_seconds = false, boolean $include_months = false ) : mixed Like distance_of_time_in_words, but where to_time is fixed to timestamp()

Private Methods

Method Description
future ( integer $distance_in_minutes, boolean $include_seconds, $distance_in_seconds ) : mixed

Method Details

__construct() public method

Constructor method
public __construct ( Symfony\Component\Translation\TranslatorInterface $translator )
$translator Symfony\Component\Translation\TranslatorInterface

distanceOfTimeInWordsFilter() public method

For example, if the distance is 47 minutes, it'll return "about 1 hour". See the source for the complete wording list. Integers are interpreted as seconds. So, by example to check the distance of time between a created user and their last login: {{ user.createdAt|distance_of_time_in_words(user.lastLoginAt) }} returns "less than a minute". Set include_seconds to true if you want more detailed approximations if distance < 1 minute Set include_months to true if you want approximations in months if days > 30
public distanceOfTimeInWordsFilter ( string | DateTime $from_time, string | DateTime $to_time = null, boolean $include_seconds = false, boolean $include_months = false ) : string
$from_time string | DateTime
$to_time string | DateTime
$include_seconds boolean True to return distance in seconds when it's lower than a minute.
$include_months boolean
return string

getFilters() public method

public getFilters ( )

getName() public method

Returns the name of the extension.
public getName ( ) : string
return string The extension name

timeAgoInWordsFilter() public method

Like distance_of_time_in_words, but where to_time is fixed to timestamp()
public timeAgoInWordsFilter ( $from_time, boolean $include_seconds = false, boolean $include_months = false ) : mixed
$from_time String or DateTime
$include_seconds boolean
$include_months boolean
return mixed

Property Details

$translator protected property

protected TranslatorInterface,Symfony\Component\Translation $translator
return Symfony\Component\Translation\TranslatorInterface