Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Use DateType in UoW to skip equivalent date values
  • Loading branch information...
commit 4a5457eb713b12d6124db9817c634533d8018044 2 parents aa94b38 + 408c6a4
@jwage jwage authored
View
12 lib/Doctrine/ODM/MongoDB/UnitOfWork.php
@@ -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
View
18 tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.