8000 [Form] Deprecate not honoring with_seconds => false for HTML5 datetime inputs in DateTimeType by fancyweb · Pull Request #49158 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Deprecate not honoring with_seconds => false for HTML5 datetime inputs in DateTimeType #49158

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

fancyweb
Copy link
Contributor
Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? yes
Tickets #48076
License MIT
Doc PR -

The with_seconds option defaults to false. It is honored when the form doesn't have data (and when the browser doesn't display the seconds). But it's not honored when the form has data because DateTimeToHtml5LocalDateTimeTransformer format the \DateTimeInterface to Y-m-d\\TH:i:s unconditionally.

In this PR, we add a new argument to DateTimeToHtml5LocalDateTimeTransformer to allow formatting to a datetime string without seconds (Y-m-d\\TH:i).

Moreover, we deprecate not setting with_seconds => true on all forms using HTML5 datetime inputs since they rely on that behavior (and it's the default value of the with_seconds option).

In Symfony 7.0, we can honor the option (by forwarding its value to the transformer) because every project should be using with_seconds => true before upgrading.

I don't really know if forcing everyone to add/set the option is the best strategy but I did not find another one.

@carsonbot carsonbot added this to the 6.3 milestone Jan 30, 2023
@fancyweb fancyweb force-pushed the form/html5-date-time-input-without-seconds branch 2 times, most recently from 097820f to 622ca4f Compare January 30, 2023 19:12
@@ -54,7 +67,7 @@ public function transform(mixed $dateTime): string
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
}

return $dateTime->format(self::HTML5_FORMAT);
return $dateTime->format($this->withSeconds ? self::HTML5_FORMAT : self::HTML5_WITHOUT_SECONDS_FORMAT);
}

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverse transform already works without seconds. We can't "remove" the seconds from a \DateTime instance so there's nothing else to do

@fancyweb fancyweb force-pushed the form/html5-date-time-input-without-seconds branch from 622ca4f to 5f80f84 Compare January 30, 2023 19:18
$options['view_timezone']
));
// Keep only the code inside this if in Symfony 7.0
if ($options['with_seconds']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure I understand these two branches. Effectively this means that starting with 7.0 setting with_seconds to false won't be supported anymore for HTML5 widgets, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 7.0, with_seconds => 8000 false won't trigger a deprecation anymore and will therefore be "allowed" and will be honored (seconds won't be displayed in the widget).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I am concerned about is that with the proposed solution we do not offer any upgrade path to opt-in to the new behaviour with with_seconds being false on 7.0 without getting a deprecation in 6.3/6.4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, because with_seconds => false currently does not work and we can't change the behavior without forcing everyone to change it to true first.

@fancyweb fancyweb force-pushed the form/html5-date-time-input-without-seconds branch from 5f80f84 to 44de252 Compare February 9, 2023 17:42
@fancyweb fancyweb force-pushed the form/html5-date-time-input-without-seconds branch from 44de252 to 60638da Compare March 29, 2023 07:37
@nicolas-grekas
Copy link
Member

Closing in favor of #50059

nicolas-grekas added a commit that referenced this pull request Apr 19, 2023
…ess "with_seconds" is explicitly set (fancyweb)

This PR was merged into the 6.3 branch.

Discussion
----------

[Form] Don't render seconds for HTML5 date pickers unless "with_seconds" is explicitly set

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #48076
| License       | MIT
| Doc PR        | -

Alternative to #49158 (commit credits due to `@fancyweb`)

I don't think we need a deprecation for this change. To me, it's a bugfix.
But merging it on 6.3 might be safer so let's do it as a new feature.

Commits
-------

93008ee [Form] Don't render seconds for HTML5 date pickers unless "with_seconds" is explicitly set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0