Commit cc67964f authored by John Voskuilen's avatar John Voskuilen
Browse files

Issue #3219111: Introduce constant OfficeHoursDateHelper::EMPTY_HOURS

parent 6602b4b6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ class OfficeHoursDatetime extends Datetime {
    if ($element === '') {
      return TRUE;
    }
    if ($element == -1) {
    if ($element == OfficeHoursDateHelper::EMPTY_HOURS) {
      // Empty hours/minutes, but comment enabled.
      // Value may be integer or text, depending on source.
      return TRUE;
+13 −4
Original line number Diff line number Diff line
@@ -13,10 +13,19 @@ use Drupal\Core\Datetime\DrupalDateTime;
class OfficeHoursDateHelper extends DateHelper {

  /**
   * The number of days per week.
   *
   * @var int
   */
  const DAYS_PER_WEEK = 7;

  /**
   * The special value for empty hours, since DB holds integers, not NULL.
   *
   * @var int
   */
  const EMPTY_HOURS = -1;

  /**
   * Gets the day number of first day of the week.
   *
@@ -136,7 +145,7 @@ class OfficeHoursDateHelper extends DateHelper {
      return NULL;
    }
    // Empty time field (negative value).
    if ($time == -1) {
    if ($time == OfficeHoursDateHelper::EMPTY_HOURS) {
      return NULL;
    }

@@ -286,8 +295,8 @@ class OfficeHoursDateHelper extends DateHelper {
  /**
   * {@inheritdoc}
   */
  public static function weekDaysOrdered($office_hours, $first_day = '') {
    $first_day = ($first_day == '') ? OfficeHoursDateHelper::getFirstDay() : $first_day;
  public static function weekDaysOrdered($office_hours, $first_day = NULL) {
    $first_day = $first_day ?? OfficeHoursDateHelper::getFirstDay();
    // Sort Weekdays; leave Exception days at bottom of list.
    foreach ($office_hours as $key => $item) {
      $new_office_hours[$key - (OfficeHoursDateHelper::DAYS_PER_WEEK * (int) ($key >= $first_day))] = $item;
@@ -357,7 +366,7 @@ class OfficeHoursDateHelper extends DateHelper {
   * Returns whether the day number is a weekday or a date (Exception day).
   *
   * @param int $day_number
   *   Day (using date_api as key (0=Sun, 6=Sat)) or exception day date.
   *   Weekday (using date_api as key (0=Sun, 6=Sat)) or Exception day date.
   *
   * @return bool
   *   False if the day_number is a (sorted) weekday (-7 until +7).
+1 −4
Original line number Diff line number Diff line
@@ -280,10 +280,7 @@ class OfficeHoursItem extends FieldItemBase {
    // And in Exception day, day can be ''.
    // Note: test every change with Week/List widget and Select/HTML5 element!
    if (isset($value['time'])) {
      if ($value['time'] === '') {
        return TRUE;
      }
      return FALSE;
      return ($value['time'] === '');
    }
    if (!isset($value['day']) && !isset($value['time'])) {
      return TRUE;
+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ class OfficeHoursItemList extends FieldItemList implements OfficeHoursItemListIn
  /**
   * {@inheritdoc}
   *
   * @todo Enable for Exception days.
   * @todo Enable isOpen() for Exception days.
   */
  public function isOpen($time = NULL) {

+2 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class OfficeHoursListWidget extends OfficeHoursWidgetBase {

    $item = $items[$delta];
    if (OfficeHoursExceptionsItem::isExceptionDay($item)) {
      // @todo Support Exception days.
      // @todo Enable List widget for Exception days.
      return [];
    }

@@ -41,7 +41,7 @@ class OfficeHoursListWidget extends OfficeHoursWidgetBase {

    $day = $default_value['day'];
    $element['value'] = [
      // @todo Set weekday number for Exception days.
      // @todo Enable weekday number/label for Exception days.
      '#day' => $day,
      // Make sure the value is shown in OfficeHoursSlot().
      '#daydelta' => 0,
Loading