Page MenuHomePhabricator

D10184.diff
No OneTemporary

D10184.diff

diff --git a/src/applications/phrequent/storage/PhrequentTimeSlices.php b/src/applications/phrequent/storage/PhrequentTimeSlices.php
--- a/src/applications/phrequent/storage/PhrequentTimeSlices.php
+++ b/src/applications/phrequent/storage/PhrequentTimeSlices.php
@@ -17,13 +17,15 @@
}
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() {
diff --git a/src/applications/phrequent/storage/__tests__/PhrequentTimeBlockTestCase.php b/src/applications/phrequent/storage/__tests__/PhrequentTimeBlockTestCase.php
--- a/src/applications/phrequent/storage/__tests__/PhrequentTimeBlockTestCase.php
+++ b/src/applications/phrequent/storage/__tests__/PhrequentTimeBlockTestCase.php
@@ -282,6 +282,30 @@
$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;

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 11, 2:02 AM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6742150
Default Alt Text
D10184.diff (1 KB)

Event Timeline