You are here

public function ActiveHours::inHours in SMS Framework 8

Same name and namespace in other branches
  1. 2.x modules/sms_user/src/ActiveHours.php \Drupal\sms_user\ActiveHours::inHours()
  2. 2.1.x modules/sms_user/src/ActiveHours.php \Drupal\sms_user\ActiveHours::inHours()

Determine if the current time of a user is within permitted hour ranges.

Parameters

\Drupal\user\UserInterface $user: A user entity.

string $now: The local time for the user. Defaults to current time.

Return value

bool Whether the current time for a user is within active hours.

Overrides ActiveHoursInterface::inHours

1 call to ActiveHours::inHours()
ActiveHours::delaySmsMessage in modules/sms_user/src/ActiveHours.php
Delay a SMS message if active hours require it to be delayed.

File

modules/sms_user/src/ActiveHours.php, line 53

Class

ActiveHours
Defines the user active hours service.

Namespace

Drupal\sms_user

Code

public function inHours(UserInterface $user, $now = 'now') {
  $this
    ->build();

  // We're in hours if active hours feature is disabled.
  if (!$this->status) {
    return TRUE;
  }
  $timezone = $user
    ->getTimeZone();
  $now = new DrupalDateTime($now, $timezone);
  foreach ($this
    ->getRanges($timezone) as $date) {
    if ($now >= $date
      ->getStartDate() && $now <= $date
      ->getEndDate()) {
      return TRUE;
    }
  }
  return FALSE;
}