Skip to content
This repository was archived by the owner on Oct 30, 2022. It is now read-only.

Commit

Permalink
Implemented age filter
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealGusBus committed Jul 6, 2016
1 parent 4b8d7da commit 590704b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Guzzlefry/Twig/AgeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@

namespace Guzzlefry\Twig;

use \DateTime;
use \Twig_Extension;
use \Twig_SimpleFilter;

/**
* Class AgeExtension
* @package Guzzlefry\Twig
*/
class AgeExtension extends Twig_Extension
{
/**
* @param DateTime $dateTime
* @return int
*/
public function age(DateTime $dateTime)
{
return $dateTime->diff(new DateTime())->format('%Y');
}

/**
* @return array
*/
public function getFilters()
{
return [
new Twig_SimpleFilter('age', [$this, 'age']),
];
}

/**
* @return string
*/
Expand Down

0 comments on commit 590704b

Please sign in to comment.