lib/Twig/Extensions/Extension/Date.php
public function diff(Twig_Environment $env, $date, $now = null)
    {
        // Convert both dates to DateTime instances.
        $date = twig_date_converter($env, $date);
        $now = twig_date_converter($env, $now);

        // Get the difference between the two DateTime objects.
        $diff = $date->diff($now);

        // Check for each interval if it appears in the $diff object.
        foreach (self::$units as $attribute => $unit) {
            $count = $diff->$attribute;

            if (0 !== $count) {
                return $this->getPluralizedInterval($count, $diff->invert, $unit);
            }
        }

        return '';
    }
public function diff(Twig_Environment $env, $date, $now = null)
    {
        // Convert both dates to DateTime instances.
        $date = twig_date_converter($env, $date);
        $now = twig_date_converter($env, $now);

        // Get the difference between the two DateTime objects.
        $diff = $date->diff($now);

        // Check for each interval if it appears in the $diff object.
        foreach (self::$units as $attribute => $unit) {
            $count = $diff->$attribute;

            if (0 !== $count) {
                return $this->getPluralizedInterval($count, $diff->invert, $unit);
            }
        }

        return '';
    }
public function diff ( Twig_Environment $ env , $ date , $ now = null ) { // Convert both dates to DateTime instances. $ date = twig_date_converter ( $ env , $ date ) ; $ now = twig_date_converter ( $ env , $ now ) ; // Get the difference between the two DateTime objects. $ diff = $ date -> diff ( $ now ) ; // Check for each interval if it appears in the $diff object. foreach ( self :: $ units as $ attribute => $ unit ) { $ count = $ diff -> $ attribute ; if ( 0 !== $ count ) { return $ this -> getPluralizedInterval ( $ count , $ diff -> invert , $ unit ) ; } } return '' ; }
Filter for converting dates to a time ago string like Facebook and Twitter has.

@param Twig_Environment $env  a Twig_Environment instance
@param string|DateTime  $date a string or DateTime object to convert
@param string|DateTime  $now  A string or DateTime object to compare with. If none given, the current time will be used.

@return string the converted time
Filter for converting dates to a time ago string like Facebook and Twitter has .