add recurring & fix until

This commit is contained in:
DavidBadura 2015-02-08 12:13:53 +00:00
parent 9ed7f6ff7c
commit 7199ad4dfa
4 changed files with 95 additions and 32 deletions

View File

@ -16,6 +16,7 @@ $task->setProject('hobby');
$task->setDue(new \DateTime('tomorrow')); $task->setDue(new \DateTime('tomorrow'));
$task->setPriority(Task::PRIORITY_HIGH); $task->setPriority(Task::PRIORITY_HIGH);
$task->addTag('next'); $task->addTag('next');
$task->setRecur('daily');
$tm->save($task); $tm->save($task);

View File

@ -14,6 +14,7 @@ class Task
const STATUS_COMPLETED = 'completed'; const STATUS_COMPLETED = 'completed';
const STATUS_DELETED = 'deleted'; const STATUS_DELETED = 'deleted';
const STATUS_WAITING = 'waiting'; const STATUS_WAITING = 'waiting';
const STATUS_RECURRING = 'recurring';
const PRIORITY_LOW = 'L'; const PRIORITY_LOW = 'L';
const PRIORITY_MEDIUM = 'M'; const PRIORITY_MEDIUM = 'M';
@ -22,28 +23,28 @@ class Task
/** /**
* @var string * @var string
* *
* @JMS\Type(name="string") * @JMS\Type("string")
*/ */
private $uuid; private $uuid;
/** /**
* @var string * @var string
* *
* @JMS\Type(name="string") * @JMS\Type("string")
*/ */
private $description; private $description;
/** /**
* @var string * @var string
* *
* @JMS\Type(name="string") * @JMS\Type("string")
*/ */
private $priority; private $priority;
/** /**
* @var string * @var string
* *
* @JMS\Type(name="string") * @JMS\Type("string")
*/ */
private $project; private $project;
@ -61,24 +62,17 @@ class Task
*/ */
private $wait; private $wait;
/**
* @var Carbon
*
* @JMS\Type("Carbon")
*/
private $until;
/** /**
* @var array * @var array
* *
* @JMS\Type(name="array<string>") * @JMS\Type("array<string>")
*/ */
private $tags; private $tags;
/** /**
* @var float * @var float
* *
* @JMS\Type(name="float") * @JMS\Type("float")
*/ */
private $urgency; private $urgency;
@ -89,6 +83,19 @@ class Task
*/ */
private $entry; private $entry;
/**
* @var string
*
* @JMS\Type("string")
*/
private $recur;
/**
* @var Carbon
*
* @JMS\Type("Carbon")
*/
private $until;
/** /**
* @var Carbon * @var Carbon
@ -107,7 +114,7 @@ class Task
/** /**
* @var string * @var string
* *
* @JMS\Type(name="string") * @JMS\Type("string")
*/ */
private $status; private $status;
@ -209,22 +216,6 @@ class Task
$this->wait = $this->parseDateTime($wait); $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 * @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 * @return \DateTime
*/ */
@ -341,6 +364,14 @@ class Task
return $this->status == self::STATUS_DELETED; return $this->status == self::STATUS_DELETED;
} }
/**
* @return bool
*/
public function isReccuring()
{
return $this->status == self::STATUS_RECURRING;
}
/** /**
* @param string|\DateTime|null $date * @param string|\DateTime|null $date
* @return \DateTime|null * @return \DateTime|null

View File

@ -163,6 +163,7 @@ class TaskManager
*/ */
private function export($filter = null) private function export($filter = null)
{ {
$this->update();
$json = $this->taskwarrior->export($filter); $json = $this->taskwarrior->export($filter);
return $this->getSerializer()->deserialize($json, 'array<DavidBadura\Taskwarrior\Task>', 'json'); return $this->getSerializer()->deserialize($json, 'array<DavidBadura\Taskwarrior\Task>', 'json');
@ -211,6 +212,18 @@ class TaskManager
$this->setValue($old, 'end', $new->getEnd()); $this->setValue($old, 'end', $new->getEnd());
} }
/**
*
*/
private function update()
{
try {
$this->taskwarrior->command('list');
} catch (TaskwarriorException $e) {
// to nothing
}
}
/** /**
* @param Task[] $tasks * @param Task[] $tasks
* @return Task[] * @return Task[]

View File

@ -24,6 +24,7 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
$this->tearDown();
$this->taskwarrior = new Taskwarrior(__DIR__ . '/.taskrc', __DIR__ . '/.task'); $this->taskwarrior = new Taskwarrior(__DIR__ . '/.taskrc', __DIR__ . '/.task');
$this->taskManager = new TaskManager($this->taskwarrior); $this->taskManager = new TaskManager($this->taskwarrior);
$this->taskwarrior->version(); // to initialise $this->taskwarrior->version(); // to initialise
@ -506,10 +507,27 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($task1->isWaiting()); $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() public function testUntil()
{ {
$this->markTestIncomplete('not working yet');
$task1 = new Task(); $task1 = new Task();
$task1->setDescription('foo1'); $task1->setDescription('foo1');
$task1->setUntil('+2 sec'); $task1->setUntil('+2 sec');