DateRangeAllDayHelper.php in Date all day 8
File
src/Utility/DateRangeAllDayHelper.php
View source
<?php
namespace Drupal\date_all_day\Utility;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\datetime_range\Plugin\Field\FieldType\DateRangeItem;
class DateRangeAllDayHelper {
const TIME_FORMAT = 'H:i:s';
public static function isAllDay($item) {
if ($item instanceof DateRangeItem) {
$start_date = $item
->get('value')
->getDateTime();
$end_date = $item
->get('end_value')
->getDateTime();
}
elseif (is_array($item) && isset($item['value'])) {
$start_date = $item['value'];
if (is_array($item['end_value']) && empty($item['end_value']['object'])) {
$end_date = NULL;
}
else {
$end_date = $item['end_value'];
}
}
else {
throw new \InvalidArgumentException('Argument $item should be either a Drupal\\datetime_range\\Plugin\\Field\\FieldType\\DateRangeItem object, either an array with a \\Drupal\\Core\\Datetime\\DrupalDateTime in the "value" key.');
}
$timezone = date_default_timezone_get();
return !empty($start_date) && $start_date
->format(self::TIME_FORMAT, [
'timezone' => $timezone,
]) === '00:00:00' && (empty($end_date) || $end_date
->format(self::TIME_FORMAT, [
'timezone' => $timezone,
]) === '23:59:59');
}
}