Malcolm Young commented on merge request !185 at project / smart_date

Malcolm Young
2025-09-24T16:02:53Z

why throw and then immediately catch?

I'd suggest wrapping the calls to createFromArray in the try block, and catching the exception that is thrown by core

    try {
      $min_value = $a::createFromArray($min, $timezone)->format('U');
      $max_value = $b::createFromArray($max, $timezone)->format('U');
    }
    catch (\InvalidArgumentException $e) {
      \Drupal::messenger()->addError($e->getMessage());
      $min_value = 0;
      $max_value = 0;
    }

although that code wouldn't be quite right:

1. we should provide a more user-friendly message

2. we should inject the messenger