Permalink
Browse files

Merge pull request #358 from doctrine/uow-date-comparison

Use DateType in UoW to skip equivalent date values
  • Loading branch information...
2 parents aa94b38 + 408c6a4 commit 4a5457eb713b12d6124db9817c634533d8018044 @jwage jwage committed Sep 29, 2012
@@ -741,9 +741,15 @@ private function computeOrRecomputeChangeSet(ClassMetadata $class, $document, $r
continue;
}
- // skip equivalent DateTime values
- if (($orgValue instanceof \DateTime || $actualValue instanceof \DateTime) && $orgValue == $actualValue) {
- continue;
+ // skip equivalent date values
+ if ($class->fieldMappings[$propName]['type'] === 'date') {
+ $dateType = Type::getType('date');
+ $dbOrgValue = $dateType->convertToDatabaseValue($orgValue);
+ $dbActualValue = $dateType->convertToDatabaseValue($actualValue);
+
+ if ($dbOrgValue instanceof \MongoDate && $dbActualValue instanceof \MongoDate && $dbOrgValue == $dbActualValue) {
+ continue;
+ }
}
// regular field
@@ -32,21 +32,33 @@ public function testDates()
$this->assertEquals('09/01/1985', $user->getCreatedAt()->format('m/d/Y'));
}
- public function testDateInstanceChangeDoesNotCauseUpdateIfValueIsTheSame()
+ /**
+ * @dataProvider provideEquivalentDates
+ */
+ public function testDateInstanceChangeDoesNotCauseUpdateIfValueIsTheSame($oldValue, $newValue)
{
$user = new User();
- $user->setCreatedAt(new \DateTime('1985-09-01 00:00:00'));
+ $user->setCreatedAt($oldValue);
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->getRepository(get_class($user))->findOneBy(array());
- $user->setCreatedAt(new \DateTime('1985-09-01 00:00:00'));
+ $user->setCreatedAt($newValue);
$this->dm->getUnitOfWork()->computeChangeSets();
$changeset = $this->dm->getUnitOfWork()->getDocumentChangeset($user);
$this->assertEmpty($changeset);
}
+ public function provideEquivalentDates()
+ {
+ return array(
+ array(new \DateTime('1985-09-01 00:00:00'), new \DateTime('1985-09-01 00:00:00')),
+ array(new \DateTime('2012-07-11T14:55:14-04:00'), new \DateTime('2012-07-11T19:55:14+01:00')),
+ array(new \DateTime('@1342033881'), new \MongoDate(1342033881)),
+ );
+ }
+
public function testDateInstanceValueChangeDoesCauseUpdateIfValueIsTheSame()
{
$user = new User();

0 comments on commit 4a5457e

Please sign in to comment.