From 5515fbfe01586b96db553d2fddfa9df02879a408 Mon Sep 17 00:00:00 2001 From: Toby Griffiths Date: Mon, 23 Sep 2024 20:20:17 +0100 Subject: [PATCH] Add support for time types without seconds Previously, if you try to use this guesser with a Time field without seconds, this fails because it doesn't take the withSeconds parameter into consideration. Now, this will add `input_format` = 'H:i' if `withoutSeconds` = true. --- Extension/Validator/ValidatorTypeGuesser.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Extension/Validator/ValidatorTypeGuesser.php b/Extension/Validator/ValidatorTypeGuesser.php index 72ae8ddd5..382ab5385 100644 --- a/Extension/Validator/ValidatorTypeGuesser.php +++ b/Extension/Validator/ValidatorTypeGuesser.php @@ -155,7 +155,12 @@ public function guessTypeForConstraint(Constraint $constraint): ?TypeGuess return new TypeGuess(LocaleType::class, [], Guess::HIGH_CONFIDENCE); case Time::class: - return new TypeGuess(TimeType::class, ['input' => 'string'], Guess::HIGH_CONFIDENCE); + $options = ['input' => 'string']; + if (!$constraint->withSeconds) { + $options['input_format'] = 'H:i'; + } + + return new TypeGuess(TimeType::class, $options, Guess::HIGH_CONFIDENCE); case Url::class: return new TypeGuess(UrlType::class, [], Guess::HIGH_CONFIDENCE);