Skip to content

[Validator] Clock-sensitive validators #60747

Open
@derrabus

Description

@derrabus

Description

My application uses the Range constraint to validate against relative date ranges like this:

#[Assert\Range(
    notInRangeMessage: 'Date out of range: Must not be older than 40 days and not in the future',
    min: '-40 days',
    max: 'now',
)]

When testing the application, I'd love to leverage Symfony's clock to pin the current date to a fixture. However, the RangeValidator as well as comparison validators like GreaterThanValidator and friends are not aware of the clock.

Simply making them aware of the clock won't solve the problem because we would suddenly need to distinguish between absolute date strings like 'March 1st 2025' and relative ones like '2 days ago'.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions