From 32b5f7895c544f230ddd491de2ecf282f74a52e0 Mon Sep 17 00:00:00 2001 From: Brian Buikema Date: Wed, 19 Nov 2014 16:17:34 -0700 Subject: [PATCH] Added method setIntervalForQueryingUsingExclusiveTimes and unit tests. --- .../SimpleGroupByQueryParameters.php | 28 +++++++++++++++++-- .../SimpleGroupByQueryParametersTest.php | 27 ++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tests/DruidFamiliar/Test/QueryParameters/SimpleGroupByQueryParametersTest.php 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