From 54156b988d900cf2117da85e8450b1a4532d54c8 Mon Sep 17 00:00:00 2001 From: mararual Date: Wed, 3 Jul 2019 10:17:48 -0600 Subject: [PATCH] =?UTF-8?q?REV-18227=20-=20DEVONLY=20-=20Fix=20bug=20in=20?= =?UTF-8?q?analytics-bundle=20to=20allow=20custom=20dat=E2=80=A6=20(#10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * REV-18227 - DEVONLY - Fix bug in analytics-bundle to allow custom date ranges * REV-18227 - DEVONLY - Fix bug in analytics-bundle to allow custom date ranges * REV-18227 - DEVONLY - Fix bug in analytics-bundle to allow custom date ranges * REV-18227 - DEVONLY - Fix bug in analytics-bundle to allow custom date ranges --- Lib/DateHelper.php | 9 +++++---- Test/TestCase/Helper/DateHelperTest.php | 11 ++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Lib/DateHelper.php b/Lib/DateHelper.php index 451b5cd..3acc68f 100644 --- a/Lib/DateHelper.php +++ b/Lib/DateHelper.php @@ -332,10 +332,11 @@ public static function getPeriodInfo($periodName, $time = null, $timezone = 'UTC $return = array('period' => $period, 'description' => 'Quarter To Date: ' . date('n/j/y', strtotime($period[0])) . '-' . date('n/j/y'), 'short_description' => 'Quarter To Date'); } elseif (strpos($periodName, '-') !== false) { $pieces = explode("-", $periodName); - $period[0] = ($pieces[0]); - $period[1] = ($pieces[1]); + $period[0] = date('Y-m-d', strtotime($pieces[0])); + $period[1] = 'custom'; + $period[2] = date('Y-m-d', strtotime($pieces[1])); $return = array('period' => $period, "description" => "Custom Date Range " . date('m/d/y', strtotime($period[0])) - . " - " . date('m/d/y', strtotime($period[1])), 'short_description' => 'Custom Date Range'); + . " - " . date('m/d/y', strtotime($period[2])), 'short_description' => 'Custom Date Range'); } elseif (preg_match('/l([\d]+)d/', $periodName, $matches)) { $howLong = $matches[1] - 1; $days = $matches[1]; @@ -534,4 +535,4 @@ public static function getIntervalTimestampsForES($period, $scale) { } return $timestamps; } -} \ No newline at end of file +} diff --git a/Test/TestCase/Helper/DateHelperTest.php b/Test/TestCase/Helper/DateHelperTest.php index 75d44dd..0c3717a 100644 --- a/Test/TestCase/Helper/DateHelperTest.php +++ b/Test/TestCase/Helper/DateHelperTest.php @@ -118,5 +118,14 @@ public function testGetPeriodInfo() { ); $this->assertEquals($ytdpyExpectedResults, DateHelper::getPeriodInfo('ytdpy', strtotime('December 15 2015'))); + + // Custom Date Range + $customExpectedResults = array( + 'period' => array('2014-01-01', 'custom', '2014-12-15'), + 'description' => 'Custom Date Range 01/01/14 - 12/15/14', + 'short_description' => 'Custom Date Range' + ); + + $this->assertEquals($customExpectedResults, DateHelper::getPeriodInfo('01/01/2014-12/15/2014')); } -} \ No newline at end of file +}