Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Passing a reference date causes the DateTimeToArrayTransformer to set minutes/hours when the stored value is 0 #40999

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

Closed
KDederichs opened this issue Apr 30, 2021 · 4 comments

Comments

@KDederichs
Copy link
Contributor

Symfony version(s) affected: 5.2.6 (probably others)

Description
If you pass a reference time to a TimeType field with input type array it will assume the time properties of the reference date when the field value was 0

How to reproduce

  1. Get a TimeType form field
  2. Set input to array
  3. Add a reference_date
  4. Try to set it to 0

Possible Solution
It's caused by https://github.com/symfony/form/blob/8822890bdb6267f8d1c027f697db4bd83c2afc55/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php#L170 cause empty views 0 as empty value and will thus take the value of the reference date

@Nyholm
Copy link
Member

Nyholm commented May 7, 2021

Could you help me understand why you would set the reference_date to 0? Im not familiar with that feature.

@KDederichs
Copy link
Contributor Author

KDederichs commented May 7, 2021

Not the reference_date, the minutes or hours, but it's related to this: #40998
So all of this only happens if you set a reference_date with differentiating input and model timezones in array mode.
As I described in that issue though I'm not 100% sure if it should be a thing you can do anyways.

@xabbuh
Copy link
Member

xabbuh commented May 7, 2021

I think adding a test for a use case that would currently fail in #40998 would help understanding and judging this issue.

@KDederichs
Copy link
Contributor Author

I did add a test case to both of them that would fail without the fix, took me a while to get to it sorry.

nicolas-grekas added a commit that referenced this issue May 27, 2021
…clude 0 (Kai Dederichs)

This PR was submitted for the 5.2 branch but it was squashed and merged into the 4.4 branch instead.

Discussion
----------

[Form] Use !isset for checks cause this doesn't falsely include 0

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #40999
| License       | MIT

By using isset 0 won't falsely included anymore

Commits
-------

cd541c5 [Form] Use !isset for checks cause this doesn't falsely include 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants