From 9f3ea629169fde53cf58b0ad22b0a194f4801fa9 Mon Sep 17 00:00:00 2001 From: DavidBadura Date: Thu, 23 Apr 2015 19:33:10 +0000 Subject: [PATCH] add start&stop --- src/Task.php | 25 ++++++++++++++++++++----- src/TaskManager.php | 27 +++++++++++++++++++++++++++ src/Taskwarrior.php | 16 ++++++++++++++++ tests/TaskManagerTest.php | 20 ++++++++++++++++++++ 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/Task.php b/src/Task.php index 72de2f5..b6a265d 100644 --- a/src/Task.php +++ b/src/Task.php @@ -84,6 +84,13 @@ class Task */ private $entry; + /** + * @var Carbon + * + * @JMS\Type("Carbon") + */ + private $start; + /** * @var string * @@ -186,7 +193,7 @@ class Task } /** - * @return \DateTime + * @return Carbon */ public function getDue() { @@ -202,7 +209,7 @@ class Task } /** - * @return \DateTime + * @return Carbon */ public function getWait() { @@ -284,7 +291,7 @@ class Task } /** - * @return \DateTime + * @return Carbon */ public function getUntil() { @@ -300,7 +307,7 @@ class Task } /** - * @return \DateTime + * @return Carbon */ public function getEntry() { @@ -308,7 +315,15 @@ class Task } /** - * @return \DateTime + * @return Carbon + */ + public function getStart() + { + return $this->start; + } + + /** + * @return Carbon */ public function getModified() { diff --git a/src/TaskManager.php b/src/TaskManager.php index d066c88..6a4f077 100644 --- a/src/TaskManager.php +++ b/src/TaskManager.php @@ -155,6 +155,32 @@ class TaskManager $this->refresh($task); } + /** + * @param Task $task + */ + public function start(Task $task) + { + if (!$task->getUuid()) { + return; + } + + $this->taskwarrior->start($task->getUuid()); + $this->refresh($task); + } + + /** + * @param Task $task + */ + public function stop(Task $task) + { + if (!$task->getUuid()) { + return; + } + + $this->taskwarrior->stop($task->getUuid()); + $this->refresh($task); + } + /** * @param Task $task */ @@ -313,6 +339,7 @@ class TaskManager $this->setValue($old, 'urgency', $new->getUrgency()); $this->setValue($old, 'status', $new->getStatus()); $this->setValue($old, 'modified', $new->getModified()); + $this->setValue($old, 'start', $new->getStart()); if ($new->isPending()) { // fix reopen problem $this->setValue($old, 'end', null); diff --git a/src/Taskwarrior.php b/src/Taskwarrior.php index 684e322..6d2c40d 100644 --- a/src/Taskwarrior.php +++ b/src/Taskwarrior.php @@ -62,6 +62,22 @@ class Taskwarrior $this->command('done', $filter); } + /** + * @param string $filter + */ + public function start($filter) + { + $this->command('start', $filter); + } + + /** + * @param string $filter + */ + public function stop($filter) + { + $this->command('stop', $filter); + } + /** * @param array $params */ diff --git a/tests/TaskManagerTest.php b/tests/TaskManagerTest.php index 2b513bf..6f6d29a 100644 --- a/tests/TaskManagerTest.php +++ b/tests/TaskManagerTest.php @@ -270,6 +270,26 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('DateTime', $task1->getEnd()); } + public function testStart() + { + $task1 = new Task(); + $task1->setDescription('foo1'); + + $this->taskManager->save($task1); + + $this->assertNull($task1->getStart()); + + $this->taskManager->start($task1); + $this->taskManager->save($task1); + + $this->assertInstanceOf('DateTime', $task1->getStart()); + + $this->taskManager->stop($task1); + $this->taskManager->save($task1); + + $this->assertNull($task1->getStart()); + } + public function testPending() { $task1 = new Task();