-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] DateTimeImmutable norm data in DateTime form types #25273
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
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.
You need to add tests for all the new classes you created.
class DateTimeImmutableToArrayTransformer extends BaseDateTimeTransformer | ||
{ | ||
private $pad; | ||
|
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.
no need for this empty line
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.
thanx, done
class DateTimeImmutableToLocalizedStringTransformer extends BaseDateTimeTransformer | ||
{ | ||
private $dateFormat; | ||
|
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.
same
Added tests. |
I'm not sure about the BC impact of changing the type of the norm data. I suggest adding the new input type first, without changing the norm data. |
That's what I tried to do in my PR. My change is pretty straightforward: I copied and renamed transformers and their tests and removed If we really want to make norm data immutable than I think we should do it first. If we don't - than yes, just add But with what I suggest immutable dates will be supported in the first place. Only |
you need to add the new allowed value for |
Sure! I planned to do that in a separate PR. Because it's gonna have a couple of new tests. If you wish, I can add commits right here. |
@Simperfit, could you please review my tests? |
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.
The tests looks good to me,
/** | ||
* @see BaseDateTimeTransformer::formats for available format options | ||
* | ||
* @param string $inputTimezone The name of the input timezone |
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.
I don't think you need all of this.
{ | ||
$reverseTransformer = new DateTimeImmutableToTimestampTransformer(); | ||
|
||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Form\Exception\TransformationFailedException'); |
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 you should add a new var for this.
Closed in favor of #25582. |
This PR was squashed before being merged into the 4.1-dev branch (closes #25582). Discussion ---------- [Form] Support \DateTimeImmutable | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9508 | License | MIT | Doc PR | symfony/symfony-docs#8920 This PR implements `input=datetime_immutable`. Replaces #25273. Commits ------- 034f8b2 [Form] Support \DateTimeImmutable
This PR suggests a way to use
\DateTimeImmutable
objects for norm data inDateTimeType
,DateType
andTimeType
.A complete BC layer for transformers is provided. All protected calls are also taken into account.
If this PR gets merged, we can then easily add
input=datetimeimmutable
with no model transformers to support\DateTimeImmutable
model data.