-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fix DateTimeType html5 input format. #27254
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
I don't see how this test could affect the failing travis php 5.4 test. Any hints? |
/** | ||
* Transforms a formatted string following RFC 3339 into a normalized date. | ||
* | ||
* @param string $rfc3339 Formatted string |
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 reference to RFC3339 here and anywhere else in this class is now not true anymore, is it?
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.
Why is there no code reuse going on? This is same as DateTimeToRfc3339Transformer, difference is it just makes sure last character is Z
return ''; | ||
} | ||
|
||
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) { |
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.
first is redundant
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 first is needed on PHP 5.3, isn't it?
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.
indeed
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.
@ostrolucky So the idea was to not use DateTimeToRfc3339Transformer at all, so we can deprecate it in 4.2 (see #27233)
* @author Franz Wilding <franz.wilding@me.com> | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class DateTimeToHTML5DateTimeLocalTransformer extends BaseDateTimeTransformer |
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.
should be "Html" instead of "HTML"
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.
Thx. Going to fix this.
After working on the pull request I was wondering, do we still need this fix, described in https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php#L49 Is there still a problem with supported PHP versions? If not, the view transformer could be removed at all and we could just use the default html5 format. This would be much cleaner. |
Hey! I wanted to ask if we should finalize this PR? Ich think we have two options here, first would be to do the refactoring, I suggested. Second would be to get the information, if this is still a problem in some PHP versions, or if we can remove the hack at all. I could not find any infos about a problem in a PHP version, does anyone know more about it? |
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone)); | ||
} | ||
|
||
return preg_replace('/\+00:00$/', '', $dateTime->format('c')); |
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.
Would it not make more sense to do ->format(DateTimeType::HTML5_FORMAT)
rather than preg_replace
ing format(c)?
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.
Of course not, because wrong time of format, but maybe having a different const
here with "Y-m-d\TH:i:s"
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 was taken from
symfony/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php
Line 48 in 5129c4c
return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c')); |
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 see that, but seems like it would be more efficient, and obvious what is happening, to pass to format
the format you actually want, rather than the wrong format, and editing it with regex.
This bug is stopping forms being submitted, would be great to see if it merged... |
05659f9
to
cd93b98
Compare
cd93b98
to
07b98f7
Compare
Closing in favor of #28372, thank you @franzwilding (you're still the commit author there so your contribution should end up in git history.) |
…mcfedr) This PR was merged into the 2.8 branch. Discussion ---------- [Form] Fix DateTimeType html5 input format | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27233, #27254 | License | MIT | Doc PR | N/A Fix DateTimeType' HTML input format according to HTML specs. Currently `DateTimeType` produces html with format `yyyy-MM-dd'T'HH:mm:ssZ` but the HTML5 spec expects `yyyy-MM-dd'T'HH:mm:ss` (i.e. no `Z`). Chrome presents an empty date picker meaning edits or having a default date are broken. Also the reverseTransform was expect to have a timezone attached, which it does not - and incorrectly marks it as being a UTC time in this case, instead of using the Transformers output TZ. This is same as @franzwilding #27254 but with change to just straight use of `DateTime::format` and handling TZ in reverseTransform Commits ------- e21a1a4 Added relevent links for parsing to the phpdoc 4f06f15 Add stricter checking for valid date time string 253d0a6 [Form] Fix DateTimeType html5 input format
…mcfedr) This PR was merged into the 2.8 branch. Discussion ---------- [Form] Fix DateTimeType html5 input format | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27233, #27254 | License | MIT | Doc PR | N/A Fix DateTimeType' HTML input format according to HTML specs. Currently `DateTimeType` produces html with format `yyyy-MM-dd'T'HH:mm:ssZ` but the HTML5 spec expects `yyyy-MM-dd'T'HH:mm:ss` (i.e. no `Z`). Chrome presents an empty date picker meaning edits or having a default date are broken. Also the reverseTransform was expect to have a timezone attached, which it does not - and incorrectly marks it as being a UTC time in this case, instead of using the Transformers output TZ. This is same as @franzwilding symfony/symfony#27254 but with change to just straight use of `DateTime::format` and handling TZ in reverseTransform Commits ------- e21a1a4df1 Added relevent links for parsing to the phpdoc 4f06f1524d Add stricter checking for valid date time string 253d0a683b [Form] Fix DateTimeType html5 input format
Fix DateTimeType' HTML input format according to HTML specs