πŸ‡ΊπŸ‡ΈUnited States @olivier.bouwman

Portland, Oregon
Account created on 21 January 2014, almost 11 years ago
#

Recent comments

πŸ‡ΊπŸ‡ΈUnited States olivier.bouwman Portland, Oregon
πŸ‡ΊπŸ‡ΈUnited States olivier.bouwman Portland, Oregon

Thank you so much for the super quick fix! This works for my use case.

πŸ‡ΊπŸ‡ΈUnited States olivier.bouwman Portland, Oregon

Here's a simplified version of my use case. We show wait times for locations. If a location is currently closed or was opened in the last hour, we don't show wait times. Because I have to do two isOpen checks for this use case, I had to add the $open_hours_clone = clone $location->field_open_hours; line. Without it, the result for the second isOpen is always the same as the first. I'm not sure how common this use case is but it seems like isOpen shouldn't always return the same value if a different timestamp is passed into it. Does that clarify things?

public function getWaitData($nid) {

    // See if this location is currently open according to the open hours.
    $location = Node::load($nid);
    $is_open = (int) $location->field_open_hours->isOpen();
    if (!$is_open) {
      return [
        'wait_time' => t('@disabled', ['@disabled' => self::WAIT_TIMES_DISABLED]),
      ];
    }

    // See if this location has opened in the last hour according to the open hours.
    $open_hours_clone = clone $location->field_open_hours;
    $time_one_hour_ago = \Drupal::time()->getRequestTime() - (1*60*60);
    $was_open_one_hour_ago = (int) $open_hours_clone->isOpen($time_one_hour_ago);
    if (!$was_open_one_hour_ago) {
      return [
        'wait_time' => t('@disabled', ['@disabled' => self::WAIT_TIMES_JUST_OPENED]),
      ];
    }

    // more code here....
Production build 0.71.5 2024