You are here

protected function DateRecurModularUtilityTrait::isAllDay in Recurring Date Field Modular Widgets 8

Same name and namespace in other branches
  1. 3.x src/DateRecurModularUtilityTrait.php \Drupal\date_recur_modular\DateRecurModularUtilityTrait::isAllDay()
  2. 2.x src/DateRecurModularUtilityTrait.php \Drupal\date_recur_modular\DateRecurModularUtilityTrait::isAllDay()

Determine whether a field item represents a full day.

Perspective of full day is determined by the current user [timezone].

Parameters

\Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem $item: Date recur field item.

bool $sameDay: Whether dates must be the same calendar day.

Return value

bool Whether a field item represents a full day.

Throws

\Exception If account has an invalid time zone.

1 call to DateRecurModularUtilityTrait::isAllDay()
DateRecurModularSierraWidget::formElement in src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php
Returns the form for a single field widget.

File

src/DateRecurModularUtilityTrait.php, line 214

Class

DateRecurModularUtilityTrait
Trait containing convenience methods for dealing with date recur widgets.

Namespace

Drupal\date_recur_modular

Code

protected function isAllDay(DateRecurItem $item, bool $sameDay = FALSE) : bool {
  $startDate = $item->start_date ? clone $item->start_date : NULL;
  $endDate = $item->end_date ? clone $item->end_date : NULL;
  if ($startDate && $endDate) {
    $timeZoneRaw = $this
      ->getCurrentUserTimeZone();
    $accountTimeZone = new \DateTimeZone($timeZoneRaw);
    $startDate
      ->setTimezone($accountTimeZone);
    $endDate
      ->setTimezone($accountTimeZone);

    // Calendar day is same.
    if ($sameDay && $startDate
      ->format('Y-m-d') !== $endDate
      ->format('Y-m-d')) {
      return FALSE;
    }

    // Ignore seconds when checking whether time is all day.
    return substr($startDate
      ->format('H:i'), 0, 5) === '00:00' && substr($endDate
      ->format('H:i'), 0, 5) === '23:59';
  }
  return FALSE;
}