Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14061225
D10184.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D10184.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 19, 5:39 AM (7 h, 2 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6742150
Default Alt Text
D10184.diff (1 KB)
Attached To
Mode
D10184: Fix Phrequent duration accounting
Attached
Detach File
Event Timeline
Log In to Comment