Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@matomo.org>2022-03-28 09:26:31 +0300
committerGitHub <noreply@github.com>2022-03-28 09:26:31 +0300
commit7c68bc7dd863fb2266f378d8cef93e929bbc8304 (patch)
tree328247ef938c3b9bde443048e40119b12cf7e718
parent1fad2382bd31ff0e0850fec918d8dc7b7aefb77c (diff)
Fix issue where date ranges might include too many subperiods (#18995)
* Fix issue where date ranges might include too many subperiods when including a magic keyword and a timezone * more tests
-rw-r--r--core/Period/Range.php2
-rw-r--r--tests/PHPUnit/Unit/Period/RangeTest.php42
2 files changed, 43 insertions, 1 deletions
diff --git a/core/Period/Range.php b/core/Period/Range.php
index e6b3ae1357..cdebc2711a 100644
--- a/core/Period/Range.php
+++ b/core/Period/Range.php
@@ -263,7 +263,7 @@ class Range extends Period
if (strpos($strDateEnd, '-') === false) {
$timezone = $this->timezone;
}
- $endDate = Date::factory($strDateEnd, $timezone);
+ $endDate = Date::factory($strDateEnd, $timezone)->setTime("00:00:00");
} else {
throw new Exception($this->translator->translate('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\'')));
}
diff --git a/tests/PHPUnit/Unit/Period/RangeTest.php b/tests/PHPUnit/Unit/Period/RangeTest.php
index bbb0873b87..f4eaf7366f 100644
--- a/tests/PHPUnit/Unit/Period/RangeTest.php
+++ b/tests/PHPUnit/Unit/Period/RangeTest.php
@@ -20,6 +20,12 @@ use Piwik\Period\Year;
*/
class RangeTest extends BasePeriodTest
{
+ public function setUp(): void
+ {
+ parent::setUp();
+ Date::$now = null;
+ }
+
/**
* @dataProvider getDateXPeriodsAgoProvider
*/
@@ -183,6 +189,42 @@ class RangeTest extends BasePeriodTest
}
// test range date1,date2
+ public function testRangeComma4_EndDateIncludesTodayWithTimezone()
+ {
+ Date::$now = strtotime('2020-08-01 03:00:00');
+ $range = new Range('day', '2008-01-01,today', 'Europe/Berlin');
+ $subPeriods = $range->getSubperiods();
+ $this->assertEquals('2008-01-01', $subPeriods[0]->toString());
+ $this->assertEquals('2008-01-02', $subPeriods[1]->toString());
+ $this->assertEquals('2008-01-03', $subPeriods[2]->toString());
+ $this->assertEquals('2020-08-01', end($subPeriods)->toString());
+ }
+
+ // test range date1,date2
+ public function testRangeComma5_EndDateIncludesTodayWithTimezoneAfterCurrentUTCDate()
+ {
+ Date::$now = strtotime('2020-08-01 03:00:00');
+ $range = new Range('day', '2008-01-01,today', 'Pacific/Auckland');
+ $subPeriods = $range->getSubperiods();
+ $this->assertEquals('2008-01-01', $subPeriods[0]->toString());
+ $this->assertEquals('2008-01-02', $subPeriods[1]->toString());
+ $this->assertEquals('2008-01-03', $subPeriods[2]->toString());
+ $this->assertEquals('2020-08-01', end($subPeriods)->toString());
+ }
+
+ // test range date1,date2
+ public function testRangeComma6_EndDateIncludesTodayWithTimezoneBeforeCurrentUTCDate()
+ {
+ Date::$now = strtotime('2020-08-01 03:00:00');
+ $range = new Range('day', '2008-01-01,today', 'America/New_York');
+ $subPeriods = $range->getSubperiods();
+ $this->assertEquals('2008-01-01', $subPeriods[0]->toString());
+ $this->assertEquals('2008-01-02', $subPeriods[1]->toString());
+ $this->assertEquals('2008-01-03', $subPeriods[2]->toString());
+ $this->assertEquals('2020-07-31', end($subPeriods)->toString());
+ }
+
+ // test range date1,date2
public function testRangeWeekcomma1()
{
$range = new Range('week', '2007-12-22,2008-01-03');