From 95ea071a8906073f047ca90afa9b148904dd5e5e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 30 Jun 2022 08:37:14 +0200 Subject: [PATCH 1/3] DbQuery: Accept any type in method `valueToTimestamp()` --- library/Icinga/Data/Db/DbQuery.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index 25acd8905..9a36c6bef 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -224,17 +224,17 @@ class DbQuery extends SimpleQuery protected function valueToTimestamp($value) { - if (ctype_digit($value)) { + if (is_string($value)) { + if (ctype_digit($value)) { + $value = (int) $value; + } else { + $value = strtotime($value); + } + } elseif (! is_int($value)) { $value = (int) $value; - } elseif (is_string($value)) { - $value = strtotime($value); } - if (is_int($value)) { - $value = $this->timestampForSql($value); - } - - return $value; + return $this->timestampForSql($value); } /** From e3a9b56423380e750985e971ab9b7127a6e6cf18 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 30 Jun 2022 08:39:44 +0200 Subject: [PATCH 2/3] eventgrid: Avoid passing null to string type functions --- .../monitoring/application/views/scripts/list/eventgrid.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/list/eventgrid.phtml b/modules/monitoring/application/views/scripts/list/eventgrid.phtml index aafa9b6b1..8809c533e 100644 --- a/modules/monitoring/application/views/scripts/list/eventgrid.phtml +++ b/modules/monitoring/application/views/scripts/list/eventgrid.phtml @@ -58,7 +58,7 @@ foreach ($summary as $entry) { $caption = sprintf( $settings[$column]['tooltip'], $value, - $this->formatDate(strtotime($day)) + $this->formatDate(strtotime($day ?? '')) ); $linkFilter = Filter::matchAll( Filter::expression('timestamp', '<', strtotime($day . ' 23:59:59')), From 3d159fe434f508d40d837aafb81f2c63a5161c90 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 30 Jun 2022 08:40:54 +0200 Subject: [PATCH 3/3] TimeRange: Accept strings in method `validateTime()` --- modules/monitoring/library/Monitoring/Timeline/TimeRange.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Timeline/TimeRange.php b/modules/monitoring/library/Monitoring/Timeline/TimeRange.php index 26d72505e..08c7a2c3a 100644 --- a/modules/monitoring/library/Monitoring/Timeline/TimeRange.php +++ b/modules/monitoring/library/Monitoring/Timeline/TimeRange.php @@ -119,12 +119,14 @@ class TimeRange implements Iterator /** * Return whether the given time is within this range of time * - * @param int|DateTime $time The timestamp or date and time to check + * @param string|int|DateTime $time The timestamp or date and time to check */ public function validateTime($time) { if ($time instanceof DateTime) { $dateTime = $time; + } elseif (is_string($time)) { + $dateTime = DateTime::createFromFormat('d/m/Y g:i A', $time); } else { $dateTime = new DateTime(); $dateTime->setTimestamp($time);