diff --git a/src/DruidFamiliar/QueryParameters/SimpleGroupByQueryParameters.php b/src/DruidFamiliar/QueryParameters/SimpleGroupByQueryParameters.php index 7d9e49b..f65d00b 100644 --- a/src/DruidFamiliar/QueryParameters/SimpleGroupByQueryParameters.php +++ b/src/DruidFamiliar/QueryParameters/SimpleGroupByQueryParameters.php @@ -5,6 +5,7 @@ use DruidFamiliar\Abstracts\AbstractTaskParameters; use DruidFamiliar\Exception\MissingParametersException; use DruidFamiliar\Interfaces\IDruidQueryParameters; +use DruidFamiliar\DruidTime; use DruidFamiliar\Interval; /** @@ -227,11 +228,34 @@ public function setIntervals(Interval $intervals) } /** - * @param Interval $intervals + * @param string|\DateTime|DruidTime $intervalStart + * @param string|\DateTime|DruidTime $intervalEnd */ public function setIntervalByStartAndEnd($intervalStart, $intervalEnd) { - $this->intervals = new Interval($intervalStart, $intervalEnd); + $this->setIntervals(new Interval($intervalStart, $intervalEnd)); } + /** + * Adjusts the datetime to make the interval "exclusive" of the datetime. + * e.g., given + * startDateTime=2014-06-18T12:30:01Z and + * endDateTime=2014-06-18T01:00:00Z + * return and Interval containing + * startDateTime=2014-06-18T12:30:00Z and + * endDateTime=2014-06-18T01:00:01Z + * + * @param $startDateTime + * @param $endDateTime + * @return void + */ + public function setIntervalForQueryingUsingExclusiveTimes($startDateTime, $endDateTime) + { + $adjustedStartDateTime = new \DateTime($startDateTime); + $adjustedStartDateTime->sub(new \DateInterval('PT1S')); + $adjustedEndDateTime = new \DateTime($endDateTime); + $adjustedEndDateTime->add(new \DateInterval('PT1S')); + + $this->setIntervals(new Interval($adjustedStartDateTime, $adjustedEndDateTime)); + } } \ No newline at end of file diff --git a/tests/DruidFamiliar/Test/QueryParameters/SimpleGroupByQueryParametersTest.php b/tests/DruidFamiliar/Test/QueryParameters/SimpleGroupByQueryParametersTest.php new file mode 100644 index 0000000..2184923 --- /dev/null +++ b/tests/DruidFamiliar/Test/QueryParameters/SimpleGroupByQueryParametersTest.php @@ -0,0 +1,27 @@ +getMockBuilder('DruidFamiliar\QueryParameters\SimpleGroupByQueryParameters') + ->setMethods(null) + ->getMock(); + + $origStartDateTime = '2014-06-18T12:30:01Z'; + $origEndDateTime = '2014-06-18T01:00:00Z'; + + $expectedResults = new Interval('2014-06-18T12:30:00Z', '2014-06-18T01:00:01Z'); + + $query->setIntervalForQueryingUsingExclusiveTimes($origStartDateTime, $origEndDateTime); + $results = $query->getIntervals(); + $this->assertEquals($expectedResults, $results); + } + +} \ No newline at end of file