You are here

public static function IntervalHandler::setTimePart 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::setTimePart()
  2. 2.0.x src/Module/Interval/IntervalHandler.php \Drupal\db_maintenance\Module\Interval\IntervalHandler::setTimePart()

Sets time part to $dt from $time.

Also checks, if $time is in 24 hour format H:i (HH:MM) like 23:30 or 01:00.

1 call to IntervalHandler::setTimePart()
IntervalHandler::isInInterval in src/Module/Interval/IntervalHandler.php
Checks, if $time is in interval between $time_start and $time_end.

File

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

Class

IntervalHandler
IntervalHandler class.

Namespace

Drupal\db_maintenance\Module\Interval

Code

public static function setTimePart($time, \DateTime &$dt) {
  if (!isset($time)) {
    return FALSE;
  }
  if (mb_strlen($time) != 5) {
    return FALSE;
  }
  $hour = (int) mb_substr($time, 0, 2);
  $minute = (int) mb_substr($time, 3, 2);
  if ($hour < 0 || $hour > 23) {
    return FALSE;
  }
  if ($minute < 0 || $minute > 59) {
    return FALSE;
  }
  $dt
    ->setTime($hour, $minute);
  return TRUE;
}