You are here

protected function FullCalendarController::calculateEndDateFromDuration in Smart Date 3.4.x

Same name and namespace in other branches
  1. 8.2 src/Controller/FullCalendarController.php \Drupal\smart_date\Controller\FullCalendarController::calculateEndDateFromDuration()
  2. 3.x src/Controller/FullCalendarController.php \Drupal\smart_date\Controller\FullCalendarController::calculateEndDateFromDuration()
  3. 3.0.x src/Controller/FullCalendarController.php \Drupal\smart_date\Controller\FullCalendarController::calculateEndDateFromDuration()
  4. 3.1.x src/Controller/FullCalendarController.php \Drupal\smart_date\Controller\FullCalendarController::calculateEndDateFromDuration()
  5. 3.2.x src/Controller/FullCalendarController.php \Drupal\smart_date\Controller\FullCalendarController::calculateEndDateFromDuration()
  6. 3.3.x src/Controller/FullCalendarController.php \Drupal\smart_date\Controller\FullCalendarController::calculateEndDateFromDuration()

Calculating for switch between all day and regular events.

Parameters

int $duration: Duration in minutes.

string|null $endDate: End value to populate.

string $startDate: Start value of the date.

1 call to FullCalendarController::calculateEndDateFromDuration()
FullCalendarController::updateEvent in src/Controller/FullCalendarController.php
Update the event entity based on information passed in request.

File

src/Controller/FullCalendarController.php, line 152

Class

FullCalendarController
Calendar Event Controller, overridden to handle Smart Date events.

Namespace

Drupal\smart_date\Controller

Code

protected function calculateEndDateFromDuration(int &$duration, ?string &$endDate, string $startDate) {
  if ($duration % 1440 == '1439') {
    if (empty($endDate)) {

      // This means an allday event is to become a regular event.
      $endDate = strtotime($startDate) + $this->defaultTimedEventDuration;
      $duration = $this->defaultTimedEventDuration / 60;
    }
    else {
      $endDate = strtotime($endDate) + 1439 * 60;
    }
  }
  else {
    if ($duration === "0" || $duration === 0) {

      // Can't distinguish all day vs moved, so assume still zero duration.
      $endDate = strtotime($startDate);
    }
    elseif (empty($endDate)) {

      // Dragged to be all day.
      // If https://fullcalendar.io/docs/defaultAllDayEventDuration = 1 day.
      $endDate = strtotime($startDate) + 1439 * 60;
      $duration = 1439;
    }
    else {
      $endDate = strtotime($endDate);
    }
  }
}