fix timezone problem

This commit is contained in:
DavidBadura 2015-04-22 12:31:30 +00:00
parent 09c3ea1e5e
commit c1de8d1ee3
2 changed files with 34 additions and 8 deletions

View File

@ -260,9 +260,9 @@ class TaskManager
'project' => $task->getProject(), 'project' => $task->getProject(),
'priority' => $task->getPriority(), 'priority' => $task->getPriority(),
'tags' => $task->getTags(), 'tags' => $task->getTags(),
'due' => $task->getDue() ? $task->getDue()->format('Ymd\THis\Z') : null, 'due' => $this->transformDate($task->getDue()),
'wait' => $task->getWait() ? $task->getWait()->format('Ymd\THis\Z') : null, 'wait' => $this->transformDate($task->getWait()),
'until' => $task->getUntil() ? $task->getUntil()->format('Ymd\THis\Z') : null 'until' => $this->transformDate($task->getUntil())
]; ];
if ($task->getRecurring()) { if ($task->getRecurring()) {
@ -326,6 +326,22 @@ class TaskManager
$refProp->setValue($task, $value); $refProp->setValue($task, $value);
} }
/**
* @param \DateTime $dateTime
* @return null|string
*/
private function transformDate(\DateTime $dateTime = null)
{
if (!$dateTime) {
return null;
}
$dateTime = clone $dateTime;
$dateTime->setTimezone(new \DateTimeZone('UTC'));
return $dateTime->format('Ymd\THis\Z');
}
/** /**
* @return Serializer * @return Serializer
*/ */

View File

@ -23,10 +23,20 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
*/ */
protected $taskManager; protected $taskManager;
/**
* @var string
*/
protected $taskDir;
public function setUp() public function setUp()
{ {
$this->tearDown(); $this->taskDir = __DIR__;
$this->taskwarrior = new Taskwarrior(__DIR__ . '/.taskrc', __DIR__ . '/.task');
$fs = new Filesystem();
$fs->remove($this->taskDir . '/.taskrc');
$fs->remove($this->taskDir . '/.task');
$this->taskwarrior = new Taskwarrior($this->taskDir . '/.taskrc', $this->taskDir . '/.task');
$this->taskManager = new TaskManager($this->taskwarrior); $this->taskManager = new TaskManager($this->taskwarrior);
$this->taskwarrior->version(); // to initialise $this->taskwarrior->version(); // to initialise
} }
@ -34,8 +44,8 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
public function tearDown() public function tearDown()
{ {
$fs = new Filesystem(); $fs = new Filesystem();
$fs->remove(__DIR__ . '/.taskrc'); $fs->remove($this->taskDir . '/.taskrc');
$fs->remove(__DIR__ . '/.task'); $fs->remove($this->taskDir . '/.task');
} }
public function testEmpty() public function testEmpty()
@ -707,6 +717,6 @@ class TaskManagerTest extends \PHPUnit_Framework_TestCase
*/ */
private function createDateTime($string = 'now') private function createDateTime($string = 'now')
{ {
return new \DateTime($string); return new \Carbon\Carbon($string);
} }
} }