Skip to content

Instantly share code, notes, and snippets.

@vertexvaar
Created December 13, 2018 14:22
Show Gist options
  • Select an option

  • Save vertexvaar/94c3931a631c03209cedd1c9df4c4805 to your computer and use it in GitHub Desktop.

Select an option

Save vertexvaar/94c3931a631c03209cedd1c9df4c4805 to your computer and use it in GitHub Desktop.
Flow DateTime converter with auto zero hour
<?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