I have the following entity:
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
class Quote
{
use SourceTrait;
use TimestampableEntity;
private $quoteId;
private $startDate;
private $endDate;
public function getStartDate(): ?\DateTime
{
return $this->startDate;
}
public function setStartDate(\DateTime $startDate)
{
$this->startDate = $startDate;
}
public function getEndDate(): ?\DateTime
{
return $this->endDate;
}
public function setEndDate(\DateTime $endDate)
{
$this->endDate = $endDate;
}
}
and I have this method in the QuoteRepository class:
public function createQuoteHeader(Agreement $agreement): int
{
$em = $this->getEntityManager();
$QuoteID = $this->getNewQuoteId();
$year = $agreement->getEndDate()->diff($agreement->getStartDate(), true)->y > 0
? $agreement->getEndDate()->diff($agreement->getStartDate(), true)->y
: 0;
dump($year);
dump(gettype($year));
dump($agreement->getEndDate());
$entity = new Quote();
...
$entity->setStartDate($agreement->getEndDate()->modify('+1 day'));
dump($agreement->getStartDate());
$entity->setEndDate($agreement->getEndDate()->modify("+1 day +{$year} year"));
dump($agreement->getEndDate());
...
$em->persist($entity);
$em->flush();
return $entity->getQuoteId();
}
The output from the dump() above are as follow (same order as in code):
0
"integer"
DateTime {#3005
+"date": "2017-03-21 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
DateTime {#3004
+"date": "2016-03-22 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
DateTime {#3005
+"date": "2017-03-23 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
Somehow the wrong values are being inserted in DB:
Maybe I am missing something but should not be StartDate equal to 2016-03-22 00:00:00??
