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 +}