-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator][Date] Introduce format for date constraint #58602
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
Conversation
0d114cc
to
f519cc7
Compare
Hi, CI seems in pain for 2 jobs in 2 different commit, something like : Cloning into '/home/runner/work/symfony/symfony/src/Symfony/Component/Workflow/vendor/symfony/validator'...
error: RPC failed; HTTP 504 curl 22 The requested URL returned error: 504
fatal: expected 'packfile' |
f519cc7
to
d83b2a0
Compare
CI seems to be good now |
You can achieve this using the DateTime constraint if I'm not wrong. Doing this change is basically making Date and DateTime constraints very similar. |
You are right @nicolas-grekas , so, the need it is to map Date from input of any format and apply the constraint on many format. Date constraint is freeze with Y-m-d, before this code I think about something more simple but really poor compare to the format of DateTime(Immutable) public const PATTERN_YMD = '/^Y(?<separator1>[.\-\/])m(?<separator2>[.\-\/])d$/D';
public const PATTERN_MDY = '/^m(?<separator1>[.\-\/])d(?<separator2>[.\-\/])Y$/D';
public const PATTERN_DMY = '/^d(?<separator1>[.\-\/])m(?<separator2>[.\-\/])Y$/D';
public const ACCEPTED_DATE_FORMATS_REGEX = [
'Y[.-/]m[.-/]d' => self::PATTERN_YMD,
'm[.-/]d[.-/]Y' => self::PATTERN_MDY,
'd[.-/]m[.-/]Y' => self::PATTERN_DMY,
]; I agree it could be redundant of DateTimeConstraint with the FORMAT |
So do we need this PR when you can use DateTime instead? |
So I close for redundancy |
I rethink about that : @nicolas-grekas Date constraint could be deprecated, but, we can keep the PATTERN constant to ease the migration, by precising that application have to do #[DateTimeConstraint(format: DATE_PATTERN) instead (for attribute example) ? Because if it is a duplication, maybe we have the same possibility also to do #[DateTimeConstraint(format: 'Y-m-d') maybe is valid ? Their is already 2 ways to do the same thing 🤔 |
I see no hurry in deprecating. Let's save people from doing changes of little value. |
All right, thanks for your light and advice ! |
Hi !
This is a PR to add the format for the constraint to validate a Date because it is too static for a validation and specially if we want to match a particular format of date which exist in many library ( like d/m/Y or m.d.Y ).
It is a proposal made to be able to match a given format of Date for a given value. As in PHP only DateTime(Immutable) is able to use format with all type of pattern, it seems natural to me to use it here.
Don't hesitate if you have any question.