add date features

This commit is contained in:
DavidBadura
2015-02-06 23:22:17 +00:00
parent d2596a35f0
commit eee7c668cc
4 changed files with 284 additions and 61 deletions

View File

@@ -53,6 +53,20 @@ class Task
*/
private $due;
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $wait;
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $until;
/**
* @var array
*
@@ -74,6 +88,21 @@ class Task
*/
private $entry;
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $modified;
/**
* @var \DateTime
*
* @JMS\Type(name="DateTime<'Ymd\THis\Z'>")
*/
private $end;
/**
* @var string
*
@@ -156,11 +185,43 @@ class Task
}
/**
* @param \DateTime $due
* @param \DateTime|string $due
*/
public function setDue(\DateTime $due = null)
public function setDue($due = null)
{
$this->due = $due;
$this->due = $this->parseDateTime($due);
}
/**
* @return \DateTime
*/
public function getWait()
{
return $this->wait;
}
/**
* @param \DateTime|string $wait
*/
public function setWait($wait = null)
{
$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);
}
/**
@@ -215,6 +276,22 @@ class Task
return $this->entry;
}
/**
* @return \DateTime
*/
public function getModified()
{
return $this->modified;
}
/**
* @return \DateTime
*/
public function getEnd()
{
return $this->end;
}
/**
* @return float
*/
@@ -263,6 +340,32 @@ class Task
return $this->status == self::STATUS_DELETED;
}
/**
* @param string|\DateTime|null $date
* @return \DateTime|null
* @throws TaskwarriorException
*/
private function parseDateTime($date)
{
if ($date instanceof \DateTime) {
$date = clone $date;
$date->setTimezone(new \DateTimeZone('UTC'));
return $date;
}
if (is_string($date)) {
return new \DateTime($date, new \DateTimeZone('UTC'));
}
if ($date === null) {
return null;
}
throw new TaskwarriorException();
}
/**
*
*/