protected function TwigDate::getIntervalUnits in Bamboo Twig 8.2
Same name and namespace in other branches
- 8.5 bamboo_twig_extensions/src/TwigExtension/TwigDate.php \Drupal\bamboo_twig_extensions\TwigExtension\TwigDate::getIntervalUnits()
- 8.3 bamboo_twig_extensions/src/TwigExtension/TwigDate.php \Drupal\bamboo_twig_extensions\TwigExtension\TwigDate::getIntervalUnits()
- 8.4 bamboo_twig_extensions/src/TwigExtension/TwigDate.php \Drupal\bamboo_twig_extensions\TwigExtension\TwigDate::getIntervalUnits()
Retrieve the diff between two dates for the given unit.
Parameters
\DateInterval $diff: The diff between two dates.
string $unit: The unit that we want to retreive diff.
Return value
float The differences for the given unit.
1 call to TwigDate::getIntervalUnits()
- TwigDate::diff in bamboo_twig_extensions/
src/ TwigExtension/ TwigDate.php - Filter for converting dates to a time ago string.
File
- bamboo_twig_extensions/
src/ TwigExtension/ TwigDate.php, line 144
Class
- TwigDate
- Provides bridge for Text functions and filters.
Namespace
Drupal\bamboo_twig_extensions\TwigExtensionCode
protected function getIntervalUnits(\DateInterval $diff, $unit) {
$total = 0;
switch ($unit) {
case 'y':
$total = $diff->days / 365.25 + $diff->h / 24;
break;
case 'm':
$total = $diff->days / 30 + $diff->h / 24;
break;
case 'd':
$total = $diff->days + $diff->h / 24 + $diff->i / 60;
break;
case 'h':
$total = $diff->days * 24 + $diff->h + $diff->i / 60;
break;
case 'i':
$total = ($diff->days * 24 + $diff->h) * 60 + $diff->i + $diff->s / 60;
break;
case 's':
$total = (($diff->days * 24 + $diff->h) * 60 + $diff->i) * 60 + $diff->s;
break;
}
return $total;
}