Skip to content

[Annotation] GreaterThan & DateTime #9390

Closed
@geoffrey-brier

Description

@geoffrey-brier

Hi there,

At work we wanted to check if a date (in a form) was greater than "now". The problem was that we were using annotations in our entity for the validation and (apparently) there is no "simple" way to do so.

The solutions which came to my mind were:

  • Use the "assert greater than" validator directly in the form type ($builder->add('foo', 'bar', array('constraints' => new \DateTime()))
  • Use the annotation @Assert\True on my date field and implement an isDateValid method
  • Create a dedicated annotation
  • Create an @DateTime annotation which would extends from \DateTime and could be used everywhere (in my case : @Assert\GreaterThan(value = @DateTime))

I've chosen to implement the latest of my proposal (@DateTime), it works well (IMO it is flexible, clean and reusable) and I think it could be a very good idea to implement it in symfony.
What do you think about it?
If you feel like it, I can share my work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions