Skip to content

[Validator] Clock-sensitive validators #60747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
derrabus opened this issue Jun 9, 2025 · 0 comments
Open

[Validator] Clock-sensitive validators #60747

derrabus opened this issue Jun 9, 2025 · 0 comments

Comments

@derrabus
Copy link
Member

derrabus commented Jun 9, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants