From ded022838b9f19ed56ed99459eea93d7aca104ea Mon Sep 17 00:00:00 2001
From: Matthieu Napoli <matthieu@mnapoli.fr>
Date: Wed, 21 Jan 2015 13:57:09 +1300
Subject: [PATCH] #7057 Bug on range with "last" and "previous"

---
 core/Period/Range.php | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/core/Period/Range.php b/core/Period/Range.php
index 36692dc0de..142b404a7b 100644
--- a/core/Period/Range.php
+++ b/core/Period/Range.php
@@ -182,11 +182,15 @@ class Range extends Period
                 }
             }
 
-            $lastN = $this->getMaxN($lastN);
+            if ($lastN != '') {
+                $lastN = $this->getMaxN($lastN);
 
-            // last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
-            $lastN--;
-            $lastN = abs($lastN);
+                // last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
+                $lastN--;
+                $lastN = abs($lastN);
+            } else {
+                $lastN = 0;
+            }
 
             $startDate = $endDate->addPeriod(-1 * $lastN, $period);
 
-- 
GitLab