Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Closed
wants to merge 1 commit into from

Conversation

franzwilding
Copy link
Contributor

Q A
Branch? master for features / 2.7 up to 4.0 for bug fixes
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27233
License MIT
Doc PR

Fix DateTimeType' HTML input format according to HTML specs

@franzwilding
Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor

@ostrolucky ostrolucky left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

first is redundant

Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

indeed

Copy link
Contributor Author

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
Copy link
Member

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"

Copy link
Contributor Author

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.

@franzwilding
Copy link
Contributor Author

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.

@fabpot fabpot modified the milestones: 2.7, 2.8 May 28, 2018
@franzwilding
Copy link
Contributor Author

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'));
Copy link
Contributor

@mcfedr mcfedr Jul 5, 2018

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_replaceing format(c)?

Copy link
Contributor

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was taken from

return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c'));
. I just removed the 'Z' so it becomes a valid html5 datetime-local format. The idea was to remove DateTimeToRfc3339Transformer in a second refactoring step

Copy link
Contributor

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.

@mcfedr
Copy link
Contributor

mcfedr commented Jul 5, 2018

This bug is stopping forms being submitted, would be great to see if it merged...

@nicolas-grekas nicolas-grekas changed the base branch from 2.7 to 2.8 July 26, 2018 09:41
@nicolas-grekas
Copy link
Member

Closing in favor of #28372, thank you @franzwilding (you're still the commit author there so your contribution should end up in git history.)

nicolas-grekas added a commit that referenced this pull request Sep 17, 2018
…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
symfony-splitter pushed a commit to symfony/form that referenced this pull request Sep 17, 2018
…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
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.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.