From dbb1e01487be220753eb5d6ff1b522ab02148270 Mon Sep 17 00:00:00 2001 From: iglocska Date: Thu, 17 Jan 2019 10:12:47 +0100 Subject: [PATCH] chg: [internal] timestamp resolution for time ranges should reorder the conditions - always take from (smaller timestamp) to (larger timestamp), no matter the order which they were entered in --- app/Model/Attribute.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index 9d09c3fdb..2bc463f5f 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -3294,13 +3294,18 @@ class Attribute extends AppModel public function setTimestampConditions($timestamp, $conditions, $scope = 'Event.timestamp') { if (is_array($timestamp)) { - $timestamp[0] = $this->Event->resolveTimeDelta($timestamp[0]); - $timestamp[1] = $this->Event->resolveTimeDelta($timestamp[1]); - $conditions['AND'][] = array($scope . ' >=' => intval($timestamp[0])); - $conditions['AND'][] = array($scope . ' <=' => intval($timestamp[1])); + $timestamp[0] = intval($this->Event->resolveTimeDelta($timestamp[0])); + $timestamp[1] = intval($this->Event->resolveTimeDelta($timestamp[1])); + if ($timestamp[0] > $timestamp[1]) { + $temp = $timestamp[0]; + $timestamp[0] = $timestamp[1]; + $timestamp[1] = $temp; + } + $conditions['AND'][] = array($scope . ' >=' => $timestamp[0]); + $conditions['AND'][] = array($scope . ' <=' => $timestamp[1]); } else { - $timestamp = $this->Event->resolveTimeDelta($timestamp); - $conditions['AND'][] = array($scope . ' >=' => intval($timestamp)); + $timestamp = intval($this->Event->resolveTimeDelta($timestamp)); + $conditions['AND'][] = array($scope . ' >=' => $timestamp); } return $conditions; }