1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-11 09:22:40 +01:00
phorge-phorge/src/applications/phrequent/storage/PhrequentTimeSlices.php
epriestley c0585b7a34 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
2014-08-07 17:05:14 -07:00

39 lines
767 B
PHP

<?php
final class PhrequentTimeSlices extends Phobject {
private $objectPHID;
private $isOngoing;
private $ranges;
public function __construct($object_phid, $is_ongoing, array $ranges) {
$this->objectPHID = $object_phid;
$this->isOngoing = $is_ongoing;
$this->ranges = $ranges;
}
public function getObjectPHID() {
return $this->objectPHID;
}
public function getDuration($now) {
$total = 0;
foreach ($this->ranges as $range) {
if ($range[1] === null) {
$total += $now - $range[0];
} else {
$total += $range[1] - $range[0];
}
}
return $total;
}
public function getIsOngoing() {
return $this->isOngoing;
}
public function getRanges() {
return $this->ranges;
}
}