You are here

public static function IntervalHandler::isInInterval in DB Maintenance 7.2

Same name and namespace in other branches
  1. 8 src/Module/Interval/IntervalHandler.php \Drupal\db_maintenance\Module\Interval\IntervalHandler::isInInterval()
  2. 2.0.x src/Module/Interval/IntervalHandler.php \Drupal\db_maintenance\Module\Interval\IntervalHandler::isInInterval()

Checks, if $time is in interval between $time_start and $time_end.

1 call to IntervalHandler::isInInterval()
IntervalHandler::isTimeIntervalConfirmed in src/Module/Interval/IntervalHandler.php
Checks, if table optimization is allowed in consistency with Time Interval configuration.

File

src/Module/Interval/IntervalHandler.php, line 37
IntervalHandler class.

Class

IntervalHandler
IntervalHandler class.

Namespace

Drupal\db_maintenance\Module\Interval

Code

public static function isInInterval($datetime, $time_start, $time_end) {

  // Get current DateTime.
  $dt = new \DateTime();
  $dt
    ->setTimestamp(REQUEST_TIME);
  $dt_start = clone $dt;
  $dt_end = clone $dt;
  if (!self::setTimePart($time_start, $dt_start)) {
    return FALSE;
  }
  if (!self::setTimePart($time_end, $dt_end)) {
    return FALSE;
  }

  // Now $dt, $dt_start, $dt_end have the same day part.
  if ($dt_start <= $dt_end) {

    // No midnight between $time_start and $time_end like 01:00 - 03:00.
    if ($dt_start <= $datetime && $datetime <= $dt_end) {

      // Like more than 01:00 AND less than 03:00 (or equal).
      return TRUE;
    }
    else {
      return FALSE;
    }
  }
  else {

    // There is midnight between $time_start and $time_end like 23:00 - 01:00.
    if ($dt_start <= $datetime || $datetime <= $dt_end) {

      // Like more than 23:00 OR less than 01:00 (or equal).
      return TRUE;
    }
    else {
      return FALSE;
    }
  }
}