Skip to content

Commit

Permalink
Added method setIntervalForQueryingUsingExclusiveTimes and unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwebpt committed Nov 19, 2014
1 parent ff301c0 commit 32b5f78
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/DruidFamiliar/QueryParameters/SimpleGroupByQueryParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DruidFamiliar\Abstracts\AbstractTaskParameters;
use DruidFamiliar\Exception\MissingParametersException;
use DruidFamiliar\Interfaces\IDruidQueryParameters;
use DruidFamiliar\DruidTime;
use DruidFamiliar\Interval;

/**
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace DruidFamiliar\Test\QueryParameters;

use DruidFamiliar\Interval;
use PHPUnit_Framework_TestCase;

class SimpleGroupByQueryParametersTest extends PHPUnit_Framework_TestCase
{

public function testAdjustTimeIntervalForQueryingSuccessfullyBuildsExclusiveTimes()
{
$query = $this->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);
}

}

0 comments on commit 32b5f78

Please sign in to comment.