Created
December 13, 2018 14:22
-
-
Save vertexvaar/94c3931a631c03209cedd1c9df4c4805 to your computer and use it in GitHub Desktop.
Flow DateTime converter with auto zero hour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| trait ControllerConverterCollection { | |
| protected function setDateTimeConverterFormatForArgument(string $argumentName, string $property, string $format) | |
| { | |
| if ($this->request->hasArgument($argumentName) && $this->arguments->hasArgument($argumentName)) { | |
| if (strrpos($format, 'H') === false) { | |
| /** @var array $argument */ | |
| $argument = $this->request->getArgument($argumentName); | |
| $dateTime = \DateTime::createFromFormat($format, $argument[$property]); | |
| $dateTime->setTime(0, 0, 0); | |
| $format .= ' H:i:s'; | |
| $argument[$property] = $dateTime->format($format); | |
| $this->request->setArgument($argumentName, $argument); | |
| } | |
| $argument = $this->arguments->getArgument($argumentName); | |
| $mappingConfig = $argument->getPropertyMappingConfiguration()->forProperty($property); | |
| $mappingConfig->setTypeConverterOption( | |
| DateTimeConverter::class, | |
| DateTimeConverter::CONFIGURATION_DATE_FORMAT, | |
| $format | |
| ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment