Created
November 3, 2022 11:07
-
-
Save ivoba/000816a698db76d8a50a3573ce56ef8e to your computer and use it in GitHub Desktop.
DataTransformer to remove seconds for HTML5 datepicker with symfony forms
This file contains 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 | |
namespace App\Form; | |
use Symfony\Component\Form\DataTransformerInterface; | |
class DateTimeNoSecondsTransformer implements DataTransformerInterface | |
{ | |
public function transform(mixed $value) | |
{ | |
if (null === $value) { | |
return null; | |
} | |
return \DateTime::createFromFormat('Y-m-d H:i', $value->format('Y-m-d H:i')); | |
} | |
public function reverseTransform(mixed $value) | |
{ | |
return $value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment