1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Fix Phrequent duration accounting

Summary: Fixes T5705. This was just derp; instead of returning the duration of the first slice, return the duration of all the slices.

Test Plan: Added unit tests. Saw reasonable results in the UI.

Reviewers: btrahan, hach-que

Reviewed By: hach-que

Subscribers: epriestley

Maniphest Tasks: T5705

Differential Revision: https://secure.phabricator.com/D10184
This commit is contained in:
epriestley 2014-08-07 17:05:14 -07:00
parent 7204f9fec2
commit c0585b7a34
2 changed files with 28 additions and 2 deletions

View file

@ -17,13 +17,15 @@ final class PhrequentTimeSlices extends Phobject {
}
public function getDuration($now) {
$total = 0;
foreach ($this->ranges as $range) {
if ($range[1] === null) {
return $now - $range[0];
$total += $now - $range[0];
} else {
return $range[1] - $range[0];
$total += $range[1] - $range[0];
}
}
return $total;
}
public function getIsOngoing() {

View file

@ -282,6 +282,30 @@ final class PhrequentTimeBlockTestCase extends PhabricatorTestCase {
$ranges);
}
public function testSumTimeSlices() {
// This block has multiple closed slices.
$block = new PhrequentTimeBlock(
array(
$this->newEvent('T1', 3456, 4456)->attachPreemptingEvents(array()),
$this->newEvent('T1', 8000, 9000)->attachPreemptingEvents(array()),
));
$this->assertEqual(
2000,
$block->getTimeSpentOnObject('T1', 10000));
// This block has an open slice.
$block = new PhrequentTimeBlock(
array(
$this->newEvent('T1', 3456, 4456)->attachPreemptingEvents(array()),
$this->newEvent('T1', 8000, null)->attachPreemptingEvents(array()),
));
$this->assertEqual(
3000,
$block->getTimeSpentOnObject('T1', 10000));
}
private function newEvent($object_phid, $start_time, $end_time) {
static $id = 0;