0

I try to let the user enter contract hours. For example 40:00 contract hours.

Currently I have it working:

/**
 * @ORM\Column(type="string", nullable=true)
 * @Assert\Regex(
 *     pattern="/[0-9]{2}:[0-5]{1}[0-9]{1}/",
 *     match=true,
 *     message="Enter a correct time value, for example 37:30"
 * )
 */
private $standardFulltimeHours;

However I then need to create a service that converts the string format to a DateTime.

The DateInterval can be a solution, however I tried it in my setup and could not get it working as I liked. There's also little documentation available.

Do you have any ideas?

DelphiLynx
  • 911
  • 1
  • 16
  • 41
  • 37:30 isn't a valid time. Maybe a DateInterval is an option? Symfony 3.2 comes with a new FormType: http://symfony.com/blog/new-in-symfony-3-2-dateinterval-form-type. – Stephan Vierkant Aug 30 '16 at 14:29
  • @StephanVierkant it's just a FormType, but there's still no equivalent in Doctrine ORM. – Jakub Matczak Aug 30 '16 at 16:24
  • 1
    That's true, but it's good to know that Symfony has a FormType for it. That means many more developers are going to have the same challenge. – Stephan Vierkant Aug 31 '16 at 09:17
  • Thanks @StephanVierkant and @dragoste! I'll stick with what I have. Just a string in the entity, an extra service for parsing the time back and forth, and using the jquery-mask plugin for frontend validation. – DelphiLynx Aug 31 '16 at 10:13

0 Answers0