-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Support \DateTimeImmutable #25582
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
throw new TransformationFailedException('Expected a \DateTimeImmutable.'); | ||
} | ||
|
||
return new \DateTime($value->format(\DateTime::RFC3339)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use createFromFormat
here to remove the need for PHP to guess the date format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jvasseur , good idea, thanx.
* | ||
* @throws TransformationFailedException If the given value is not a \DateTimeImmutable | ||
*/ | ||
public function transform($value): ?\DateTime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the return type hint breaks the prototype.
* | ||
* @throws TransformationFailedException If the given value is not a \DateTime | ||
*/ | ||
public function reverseTransform($value): ?\DateTimeImmutable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the return type hint breaks the prototype.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, fixed!
Status: needs work |
Status: Needs Review |
Anything else needed here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice approach to leverage the feature without too much overhead, until we make the required change to make it the default norm format.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(small rebase needed)
73a5215
to
7721aed
Compare
Rebased. Added a changelog entry and replaced previously added If everything's good after this, I will squash commits. |
Thank you @vudaltsov. |
Are there plans to port this to at least Symfony 3.4? |
@ste93cry Since this is considered to be a new feature, it most likely won't land in 3.4, which is in bugfix-only mode. |
@ste93cry , during this week-end I will create a small bundle to add this functionality to earlier Symfony versions. |
…ateTimeType (vudaltsov) This PR was merged into the master branch. Discussion ---------- [Form] input=datetime_immutable for DateType, TimeType, DateTimeType Related to symfony/symfony#25582. Commits ------- f6bf5f2 Added input=datetime_immutable for DateType, TimeType, DateTimeType.
Created a polyfill bundle for those who want to use |
This PR implements
input=datetime_immutable
. Replaces #25273.