2

Context

On a Symfony form, I need to restrict a date field to avoid entering a date earlier than the current date.

I have seen in the Symfony official documentation that I can use the GreaterThan constraint. Here is my code :

/**
 * @var \DateTime
 * @Assert\DateTime()
 * @Assert\GreaterThan("now UTC+2")
 *
 * @ORM\Column(type="datetime", name="start_date")
 */
private $startDate;

I have setup my timezone the following way:

  • In the OroPlatform dashboard : System > Configuration > Localization
  • I have put the timezone in php.ini of the Symfony Web Server

My timezone is Europe/Paris

Issue

I have done all the requirements described in the Context section. But, the js validator not working.

enter image description here

I'm living in France so my timezone is Europe/Paris. If I do a dump(new \Datetime('now')) the current datetime value is 10H48

How to adapt the js red alert to set the current js timezone to Europe/Paris ?

I have tried to run these commands symfony console cache:clear and symfony console oro:localization:dump but it doesn't change the timezone in the red message.

Louis Bertin
  • 552
  • 2
  • 12

1 Answers1

1

I have finally found what I have done wrong.

If your server and your Oro app localization is correctly configured. You don't have to force the locale in the entity constraint.

So, change :

/**
* @var \DateTime
* @Assert\GreaterThan("now UTC+2")
*
* @ORM\Column(type="datetime", name="start_date")
*/
private $startDate;

to

/**
* @var \DateTime
* @Assert\GreaterThan("now")
*
* @ORM\Column(type="datetime", name="start_date")
*/
private $startDate;

Don't forget to clear your cache : symfony console cache:clear

Louis Bertin
  • 552
  • 2
  • 12