[Form] Fix DateTimeType html5 input format#28372
Conversation
374dfbf to
67a95f4
Compare
| use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer; | ||
| use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain; | ||
| use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; | ||
| use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToHTML5DateTimeLocalTransformer; |
There was a problem hiding this comment.
case mismatch (see failing tests): should be Html5
67a95f4 to
8839532
Compare
nicolas-grekas
left a comment
There was a problem hiding this comment.
LGTM with just one minor comment
| */ | ||
| class DateTimeToHtml5DateTimeLocalTransformer extends BaseDateTimeTransformer | ||
| { | ||
| const HTML5_FORMAT = "Y-m-d\TH:i:s"; |
There was a problem hiding this comment.
Fixed, I've also put '\T' in the middle, as it looks more correct, it works with single \ because \T is not a valid combo, but really for a literal \ it should be \\
8839532 to
253d0a6
Compare
|
This is a bit confusing:
|
|
@javiereguiluz The problem is, that Chrome do not support |
|
I see. In the past, we usually ignored issues like this considering them as browsers bugs (I remember a problem with a Safari-only behavior). But this is frustrating for users and Chrome is the most popular browser ... so it will be a tough decision. |
|
@javiereguiluz I think in this case it is less a browser specific hack and more a more correct implementation of the datetime-local draft specs. I think the whole idea of datetime-local is to be a datetime field without a timezone, this is also the description of the datetime-local field: https://www.w3.org/TR/2012/WD-html-markup-20120315/input.datetime-local.html Also, when you see the reference of the date + time format (https://www.w3.org/TR/2012/WD-html-markup-20120315/datatypes.html#form.data.datetime-local) it clearly says that there should not be a timezone suffix. |
|
@franzwilding thanks for the details. It's more clear to me now. Approved it! |
|
I refered to the whatwg spec, which does not include |
| } | ||
|
|
||
| try { | ||
| $dateTime = new \DateTime($dateTimeLocal, new \DateTimeZone($this->outputTimezone)); |
There was a problem hiding this comment.
Makes sense, I've added something similar here.
d6f0029 to
e21a1a4
Compare
|
Thank you @mcfedr. |
…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
|
Could anyone please have a look at why this PR makes tests for 4.1 to fail? |
This PR was submitted for the master branch but it was merged into the 4.1 branch instead (closes #28504). Discussion ---------- [Form] Fix expected values in datetime-local test | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28372 | License | MIT | Doc PR | N/A Commits ------- 5ed8b27 Fix expected values in datetime-local test
Fix DateTimeType' HTML input format according to HTML specs. Currently
DateTimeTypeproduces html with formatyyyy-MM-dd'T'HH:mm:ssZbut the HTML5 spec expectsyyyy-MM-dd'T'HH:mm:ss(i.e. noZ). 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::formatand handling TZ in reverseTransform