◆ __construct()
Twig_Extensions_Extension_Date::__construct |
( |
TranslatorInterface |
$translator = null | ) |
|
◆ 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 | $env | a Twig_Environment instance |
string | DateTime | $date | a string or DateTime object to convert |
string | DateTime | $now | A 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.
57 {
58
61
62
63 $diff = $date->diff($now);
64
65
66 foreach (self::$units as $attribute => $unit) {
67 $count = $diff->$attribute;
68
69 if (0 !== $count) {
71 }
72 }
73
74 return '';
75 }
getPluralizedInterval($count, $invert, $unit)
twig_date_converter(Twig_Environment $env, $date=null, $timezone=null)
Converts an input to a DateTime instance.
References $env, getPluralizedInterval(), and twig_date_converter().
◆ getFilters()
Twig_Extensions_Extension_Date::getFilters |
( |
| ) |
|
{Returns a list of filters to add to the existing list.
- Returns
- Twig_SimpleFilter[]
}
Reimplemented from Twig_Extension.
Definition at line 40 of file Date.php.
41 {
42 return array(
43 new Twig_SimpleFilter(
'time_diff', array($this,
'diff'), array(
'needs_environment' =>
true)),
44 );
45 }
Represents a template filter.
◆ getName()
Twig_Extensions_Extension_Date::getName |
( |
| ) |
|
{
- Deprecated:
- since 1.26 (to be removed in 2.0), not used anymore internally
}
Reimplemented from Twig_Extension.
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.
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
References $id.
Referenced by diff().
◆ $translator
Twig_Extensions_Extension_Date::$translator |
|
private |
◆ $units
Twig_Extensions_Extension_Date::$units |
|
static |
Initial value:= array(
'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:
- libs/composer/vendor/twig/extensions/lib/Twig/Extensions/Extension/Date.php