diff --git a/README.md b/README.md index 5eebbc7..a63ecbb 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ $task->setProject('hobby'); $task->setDue(new \DateTime('tomorrow')); $task->setPriority(Task::PRIORITY_HIGH); $task->addTag('next'); +$task->setRecur('daily'); $tm->save($task); diff --git a/src/Task.php b/src/Task.php index e2888dd..483ea5a 100644 --- a/src/Task.php +++ b/src/Task.php @@ -14,6 +14,7 @@ class Task const STATUS_COMPLETED = 'completed'; const STATUS_DELETED = 'deleted'; const STATUS_WAITING = 'waiting'; + const STATUS_RECURRING = 'recurring'; const PRIORITY_LOW = 'L'; const PRIORITY_MEDIUM = 'M'; @@ -22,28 +23,28 @@ class Task /** * @var string * - * @JMS\Type(name="string") + * @JMS\Type("string") */ private $uuid; /** * @var string * - * @JMS\Type(name="string") + * @JMS\Type("string") */ private $description; /** * @var string * - * @JMS\Type(name="string") + * @JMS\Type("string") */ private $priority; /** * @var string * - * @JMS\Type(name="string") + * @JMS\Type("string") */ private $project; @@ -61,24 +62,17 @@ class Task */ private $wait; - /** - * @var Carbon - * - * @JMS\Type("Carbon") - */ - private $until; - /** * @var array * - * @JMS\Type(name="array") + * @JMS\Type("array") */ private $tags; /** * @var float * - * @JMS\Type(name="float") + * @JMS\Type("float") */ private $urgency; @@ -89,6 +83,19 @@ class Task */ private $entry; + /** + * @var string + * + * @JMS\Type("string") + */ + private $recur; + + /** + * @var Carbon + * + * @JMS\Type("Carbon") + */ + private $until; /** * @var Carbon @@ -107,7 +114,7 @@ class Task /** * @var string * - * @JMS\Type(name="string") + * @JMS\Type("string") */ private $status; @@ -209,22 +216,6 @@ class Task $this->wait = $this->parseDateTime($wait); } - /** - * @return \DateTime - */ - public function getUntil() - { - return $this->until; - } - - /** - * @param \DateTime|string $until - */ - public function setUntil($until = null) - { - $this->until = $this->parseDateTime($until); - } - /** * @return array */ @@ -269,6 +260,38 @@ class Task } } + /** + * @return string + */ + public function getRecur() + { + return $this->recur; + } + + /** + * @param string $recur + */ + public function setRecur($recur) + { + $this->recur = $recur; + } + + /** + * @return \DateTime + */ + public function getUntil() + { + return $this->until; + } + + /** + * @param \DateTime|string $until + */ + public function setUntil($until = null) + { + $this->until = $this->parseDateTime($until); + } + /** * @return \DateTime */ @@ -341,6 +364,14 @@ class Task return $this->status == self::STATUS_DELETED; } + /** + * @return bool + */ + public function isReccuring() + { + return $this->status == self::STATUS_RECURRING; + } + /** * @param string|\DateTime|null $date * @return \DateTime|null diff --git a/src/TaskManager.php b/src/TaskManager.php index 702b0dc..dddeeff 100644 --- a/src/TaskManager.php +++ b/src/TaskManager.php @@ -163,6 +163,7 @@ class TaskManager */ private function export($filter = null) { + $this->update(); $json = $this->taskwarrior->export($filter); return $this->getSerializer()->deserialize($json, 'array', 'json'); @@ -211,6 +212,18 @@ class TaskManager $this->setValue($old, 'end', $new->getEnd()); } + /** + * + */ + private function update() + { + try { + $this->taskwarrior->command('list'); + } catch (TaskwarriorException $e) { + // to nothing + } + } + /** * @param Task[] $tasks * @return Task[] diff --git a/tests/TaskManagerTest.php b/tests/TaskManagerTest.php index 768c3ad..d3272b6 100644 --- a/tests/TaskManagerTest.php +++ b/tests/TaskManagerTest.php @@ -24,6 +24,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { + $this->tearDown(); $this->taskwarrior = new Taskwarrior(__DIR__ . '/.taskrc', __DIR__ . '/.task'); $this->taskManager = new TaskManager($this->taskwarrior); $this->taskwarrior->version(); // to initialise @@ -506,10 +507,27 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase $this->assertFalse($task1->isWaiting()); } + public function testRecurring() + { + $task1 = new Task(); + $task1->setDescription('foo1'); + $task1->setDue('tomorrow'); + $task1->setRecur('daily'); + + $this->taskManager->save($task1); + + $this->assertCount(2, $this->taskManager->filterAll()); + + $this->assertTrue($task1->isReccuring()); + + $result = $this->taskManager->filter(); + $this->assertCount(1, $result); + + $this->assertTrue($result[0]->isPending()); + } + public function testUntil() { - $this->markTestIncomplete('not working yet'); - $task1 = new Task(); $task1->setDescription('foo1'); $task1->setUntil('+2 sec');