Skip to content
Snippets Groups Projects

Add a twig filter to check if a date range is all day

2 files
+ 45
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 40
0
<?php
namespace Drupal\smart_date\Twig\Extension;
use Drupal\smart_date\SmartDateTrait;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* Twig Extension class for Smart Date.
*/
class SmartDateExtension extends AbstractExtension {
/**
* {@inheritDoc}
*/
public function getFunctions() {
return [
new TwigFunction('is_all_day', [$this, 'smartDateIsAllDay']),
];
}
/**
* Evaluates whether or not a provided range is "all day".
*
* @param object $start_ts
* A timestamp.
* @param object $end_ts
* A timestamp.
* @param string|null $timezone
* An optional timezone override.
*
* @return bool
* Whether or not the timestamps are considered all day by Smart Date.
*/
public function smartDateIsAllDay($start_ts, $end_ts, $timezone = NULL) {
return SmartDateTrait::isAllDay($start_ts, $end_ts, $timezone);
}
}
Loading