8000 [Validator] Replace Date, DateTime and Time by Timestamp · Issue #11925 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Validator] Replace Date, DateTime and Time by Timestamp #11925
Closed
@webmozart

Description

@webmozart

At the moment, we have three constraints for validating date/time values:

  • Date accepts \DateTime instances and 'Y-m-d' strings
  • DateTime accepts \DateTime instances and 'Y-m-d H:i:s' strings
  • Time accepts \DateTime instances and 'H:i:s' strings

I think that's a bit confusing. Usually, a value should not be a \DateTime or a string, but either of them; if it is a string, it should usually match a specific pattern.

Therefore I propose to deprecate all three constraints. The \DateTime case can be solved with the Type constraint already:

/**
 * @Assert\Type('\DateTime')
 */
private $createdAt;

The second case would be covered by a new Timestamp constraint which accepts a format as argument as supported by PHP:

/**
 * @Assert\Timestamp('Y-m-d')
 */
private $createdAt;

/**
 * @Assert\Timestamp('c')
 */ 
private $iso8601Date;

This would fix #11919 and replace #11821.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)Validator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0