You are here

protected function OfficeHoursFormatterTrait::keepCurrentDay in Office Hours 8

Formatter: remove all days, except for today.

Parameters

array $office_hours: Office hours array.

Return value

array Reformatted office hours array.

1 call to OfficeHoursFormatterTrait::keepCurrentDay()
OfficeHoursFormatterTrait::getRows in src/OfficeHoursFormatterTrait.php
Returns the items of a field.

File

src/OfficeHoursFormatterTrait.php, line 262

Class

OfficeHoursFormatterTrait
Factors out OfficeHoursItemList->getItems()->getRows().

Namespace

Drupal\office_hours

Code

protected function keepCurrentDay(array $office_hours) {
  $new_office_hours = [];

  // Get day_number (0=Sun, 6=Sat).
  $today = (int) idate('w', $_SERVER['REQUEST_TIME']);
  foreach ($office_hours as $info) {
    if ($info['startday'] == $today) {
      $new_office_hours[$today] = $info;
    }
  }
  return $new_office_hours;
}