Skip to content

Commit

Permalink
Do change timezone of DateTime object assc. with node.
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Mar 31, 2016
1 parent 43fed3a commit ac7db08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Jackalope/Transport/DoctrineDBAL/Client.php
Expand Up @@ -1157,6 +1157,10 @@ private function propsToXML($properties)
}
foreach ((array) $values as $key => $date) {
if ($date instanceof \DateTime) {
// do not modify the instance which is associated with the node.
$date = clone $date;

// normalize to UTC for storage.
$date->setTimezone(new \DateTimeZone('UTC'));
}
$values[$key] = $date;
Expand Down
16 changes: 16 additions & 0 deletions tests/Jackalope/Transport/DoctrineDBAL/ClientTest.php
Expand Up @@ -525,4 +525,20 @@ public function testCopy()
$this->assertEquals($child1['props'], $child2['props']);
$this->assertEquals($child1['numerical_props'], $child2['numerical_props']);
}

/**
* The date value should not change when saving.
*/
public function testDate()
{
$rootNode = $this->session->getNode('/');
$child1 = $rootNode->addNode('child1');
$date = new \DateTime();
$before = $date->format('c');
$child1->setProperty('date', $date);
$this->session->save();
$after = $date->format('c');

$this->assertEquals($before, $after);
}
}

0 comments on commit ac7db08

Please sign in to comment.