Skip to content

Commit

Permalink
TimeGrid\Util: Throw in diffHours if $to is smaller than $from
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Jun 11, 2024
1 parent 141792e commit 606a1fb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/Notifications/Widget/TimeGrid/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Module\Notifications\Widget\TimeGrid;

use DateTime;
use InvalidArgumentException;

final class Util
{
Expand All @@ -14,6 +15,9 @@ final class Util
public static function diffHours(DateTime $from, DateTime $to)
{
$diff = $from->diff($to);
if ($diff->invert) {
throw new InvalidArgumentException('The end date must be after the start date');
}

$hours = 0;
if ($diff->h > 0) {
Expand Down

0 comments on commit 606a1fb

Please sign in to comment.