ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Extensions_Extension_Date Class Reference
+ Inheritance diagram for Twig_Extensions_Extension_Date:
+ Collaboration diagram for Twig_Extensions_Extension_Date:

Public Member Functions

 __construct (TranslatorInterface $translator=null)
 
 getFilters ()
 {Returns a list of filters to add to the existing list.
Returns
Twig_SimpleFilter[]
} More...
 
 diff (Twig_Environment $env, $date, $now=null)
 Filter for converting dates to a time ago string like Facebook and Twitter has. More...
 
 getName ()
 {Returns the name of the extension.
Returns
string The extension name
Deprecated:
since 1.26 (to be removed in 2.0), not used anymore internally
} More...
 
- Public Member Functions inherited from Twig_Extension
 initRuntime (Twig_Environment $environment)
 
 getTokenParsers ()
 Returns the token parser instances to add to the existing list. More...
 
 getNodeVisitors ()
 Returns the node visitor instances to add to the existing list. More...
 
 getFilters ()
 Returns a list of filters to add to the existing list. More...
 
 getTests ()
 Returns a list of tests to add to the existing list. More...
 
 getFunctions ()
 Returns a list of functions to add to the existing list. More...
 
 getOperators ()
 Returns a list of operators to add to the existing list. More...
 
 getGlobals ()
 
 getName ()
 

Static Public Attributes

static $units
 

Protected Member Functions

 getPluralizedInterval ($count, $invert, $unit)
 

Private Attributes

 $translator
 

Detailed Description

Author
Robin van der Vleuten robin.nosp@m.vdvl.nosp@m.euten.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition at line 16 of file Date.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Extensions_Extension_Date::__construct ( TranslatorInterface  $translator = null)

Definition at line 32 of file Date.php.

References $translator.

33  {
34  $this->translator = $translator;
35  }

Member Function Documentation

◆ diff()

Twig_Extensions_Extension_Date::diff ( Twig_Environment  $env,
  $date,
  $now = null 
)

Filter for converting dates to a time ago string like Facebook and Twitter has.

Parameters
Twig_Environment$enva Twig_Environment instance
string | DateTime$datea string or DateTime object to convert
string | DateTime$nowA string or DateTime object to compare with. If none given, the current time will be used.
Returns
string the converted time

Definition at line 56 of file Date.php.

References getPluralizedInterval(), and twig_date_converter().

57  {
58  // Convert both dates to DateTime instances.
59  $date = twig_date_converter($env, $date);
60  $now = twig_date_converter($env, $now);
61 
62  // Get the difference between the two DateTime objects.
63  $diff = $date->diff($now);
64 
65  // Check for each interval if it appears in the $diff object.
66  foreach (self::$units as $attribute => $unit) {
67  $count = $diff->$attribute;
68 
69  if (0 !== $count) {
70  return $this->getPluralizedInterval($count, $diff->invert, $unit);
71  }
72  }
73 
74  return '';
75  }
getPluralizedInterval($count, $invert, $unit)
Definition: Date.php:77
twig_date_converter(Twig_Environment $env, $date=null, $timezone=null)
Converts an input to a DateTime instance.
Definition: Core.php:422
+ Here is the call graph for this function:

◆ getFilters()

Twig_Extensions_Extension_Date::getFilters ( )

{Returns a list of filters to add to the existing list.

Returns
Twig_SimpleFilter[]
}

Implements Twig_ExtensionInterface.

Definition at line 40 of file Date.php.

References array.

41  {
42  return array(
43  new Twig_SimpleFilter('time_diff', array($this, 'diff'), array('needs_environment' => true)),
44  );
45  }
Represents a template filter.
Create styles array
The data for the language used.

◆ getName()

Twig_Extensions_Extension_Date::getName ( )

{Returns the name of the extension.

Returns
string The extension name
Deprecated:
since 1.26 (to be removed in 2.0), not used anymore internally
}

Implements Twig_ExtensionInterface.

Definition at line 95 of file Date.php.

96  {
97  return 'date';
98  }

◆ getPluralizedInterval()

Twig_Extensions_Extension_Date::getPluralizedInterval (   $count,
  $invert,
  $unit 
)
protected

Definition at line 77 of file Date.php.

References $id, and array.

Referenced by diff().

78  {
79  if ($this->translator) {
80  $id = sprintf('diff.%s.%s', $invert ? 'in' : 'ago', $unit);
81 
82  return $this->translator->transChoice($id, $count, array('%count%' => $count), 'date');
83  }
84 
85  if (1 !== $count) {
86  $unit .= 's';
87  }
88 
89  return $invert ? "in $count $unit" : "$count $unit ago";
90  }
if(!array_key_exists('StateId', $_REQUEST)) $id
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

Field Documentation

◆ $translator

Twig_Extensions_Extension_Date::$translator
private

Definition at line 30 of file Date.php.

Referenced by __construct().

◆ $units

Twig_Extensions_Extension_Date::$units
static
Initial value:
'y' => 'year',
'm' => 'month',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
)

Definition at line 18 of file Date.php.


The documentation for this class was generated from the following file: