everything changed to datetime

This commit is contained in:
Julie Lenaerts 2021-08-10 10:56:45 +02:00
parent b74f9cf5dc
commit fb43980a2a
3 changed files with 13 additions and 12 deletions

View File

@ -35,9 +35,9 @@ final class AsideActivity implements TrackUpdateInterface, TrackCreationInterfac
private \Chill\MainBundle\Entity\User $createdBy; private \Chill\MainBundle\Entity\User $createdBy;
/** /**
* @ORM\Column(type="datetime_immutable") * @ORM\Column(type="datetime")
*/ */
private \DateTimeInterface $createdAt; private $createdAt;
/** /**
* @ORM\ManyToOne(targetEntity=User::class) * @ORM\ManyToOne(targetEntity=User::class)
@ -45,9 +45,9 @@ final class AsideActivity implements TrackUpdateInterface, TrackCreationInterfac
private \Chill\MainBundle\Entity\User $updatedBy; private \Chill\MainBundle\Entity\User $updatedBy;
/** /**
* @ORM\Column(type="datetime_immutable", nullable=true) * @ORM\Column(type="datetime", nullable=true)
*/ */
private \DateTimeInterface $updatedAt; private $updatedAt;
/** /**
* @ORM\ManyToOne(targetEntity=User::class) * @ORM\ManyToOne(targetEntity=User::class)
@ -57,14 +57,14 @@ final class AsideActivity implements TrackUpdateInterface, TrackCreationInterfac
private \Chill\MainBundle\Entity\User $agent; private \Chill\MainBundle\Entity\User $agent;
/** /**
* @ORM\Column(type="datetime_immutable") * @ORM\Column(type="datetime")
*/ */
private \DateTimeInterface $date; private $date;
/** /**
* @ORM\Column(type="time", nullable=true) * @ORM\Column(type="time", nullable=true)
*/ */
private ?\DateTime $duration = null; private ?\DateTimeInterface $duration = null;
/** /**
* @ORM\Column(type="string", length=100, nullable=true) * @ORM\Column(type="string", length=100, nullable=true)
@ -165,12 +165,12 @@ final class AsideActivity implements TrackUpdateInterface, TrackCreationInterfac
return $this; return $this;
} }
public function getDuration(): ?\DateTime public function getDuration(): ?\DateTimeInterface
{ {
return $this->duration; return $this->duration;
} }
public function setDuration(?\DateTime $duration): self public function setDuration(?\DateTimeInterface $duration): self
{ {
$this->duration = $duration; $this->duration = $duration;

View File

@ -12,7 +12,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity * @ORM\Entity
* @ORM\Table(schema="chill_asideactivity") * @ORM\Table(schema="chill_asideactivity")
*/ */
final class AsideActivityCategory class AsideActivityCategory
{ {
/** /**
* @ORM\Id * @ORM\Id

View File

@ -55,7 +55,7 @@ final class AsideActivityFormType extends AbstractType
->add('date', ChillDateType::class, ->add('date', ChillDateType::class,
[ [
'label' => 'date', 'label' => 'date',
'data' => new \DateTimeImmutable(), 'data' => new \DateTime(),
//SETTING RANGE ONLY POSSIBLE WITH WIDGET 'CHOICE' AND NOT 'SINGLE_TEXT'? //SETTING RANGE ONLY POSSIBLE WITH WIDGET 'CHOICE' AND NOT 'SINGLE_TEXT'?
// 'widget' => 'choice', // 'widget' => 'choice',
// 'years' => range(2020, date('Y')), // 'years' => range(2020, date('Y')),
@ -96,13 +96,14 @@ final class AsideActivityFormType extends AbstractType
// set the timezone to GMT, and fix the difference between current and GMT // set the timezone to GMT, and fix the difference between current and GMT
// the datetimetransformer will then handle timezone as GMT // the datetimetransformer will then handle timezone as GMT
$timezoneUTC = new \DateTimeZone('GMT'); $timezoneUTC = new \DateTimeZone('GMT');
/* @var $data \DateTime */ /* @var $data \DateTimeImmutable */
$data = $formEvent->getData() === NULL ? $data = $formEvent->getData() === NULL ?
\DateTime::createFromFormat('U', 300) : \DateTime::createFromFormat('U', 300) :
$formEvent->getData(); $formEvent->getData();
$seconds = $data->getTimezone()->getOffset($data); $seconds = $data->getTimezone()->getOffset($data);
$data->setTimeZone($timezoneUTC); $data->setTimeZone($timezoneUTC);
$data->add(new \DateInterval('PT'.$seconds.'S')); $data->add(new \DateInterval('PT'.$seconds.'S'));
dump($data);
// test if the timestamp is in the choices. // test if the timestamp is in the choices.
// If not, recreate the field with the new timestamp // If not, recreate the field with the new timestamp