/**
  * @param PreUpdateEventArgs $event
  */
 public function preUpdate(PreUpdateEventArgs $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof CalendarEvent) {
         if ($event->hasChangedField('start') || $event->hasChangedField('reminder')) {
             $needChangeSetsComputing = false;
             if ($event->hasChangedField('reminder')) {
                 if ($event->getNewValue('reminder')) {
                     $start = $event->hasChangedField('start') ? $event->getNewValue('start') : $entity->getStart();
                     $entity->setRemindAt($this->remindTimeCalculator->calculateRemindAt($start));
                 } else {
                     $entity->setRemindAt(null);
                 }
                 if ($entity->getReminded()) {
                     $entity->setReminded(false);
                 }
                 $needChangeSetsComputing = true;
             } else {
                 if ($entity->getReminder()) {
                     $entity->setRemindAt($this->remindTimeCalculator->calculateRemindAt($event->getNewValue('start')));
                     $needChangeSetsComputing = true;
                 }
                 if ($entity->getReminded()) {
                     $entity->setReminded(false);
                     $needChangeSetsComputing = true;
                 }
             }
             if ($needChangeSetsComputing) {
                 $em = $event->getEntityManager();
                 $uow = $em->getUnitOfWork();
                 $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('OroCalendarBundle:CalendarEvent'), $entity);
             }
         }
     }
 }
 public function testCalculateRemindAt()
 {
     $calculator = new RemindTimeCalculator(15);
     $date = new \DateTime();
     $expected = clone $date;
     $expected->sub(new \DateInterval('PT15M'));
     $this->assertEquals($expected, $calculator->calculateRemindAt($date));
 }