Skip to content
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

[Form] reverse transform RFC 3339 formatted dates #28712

Merged
merged 1 commit into from Oct 14, 2018

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Oct 3, 2018

Q A
Branch? 2.8
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #28699
License MIT
Doc PR

Technically, dates formatted according to the HTML specifications do not
contain any timezone information. But since our DateTimeType used to
contain this information in the passed, users had configure their JS
libraries to accept (and create) dates in that format.

To not break BC we should accept these dates and silently ignore the
additional timezone information.

@@ -81,7 +81,7 @@ public function reverseTransform($dateTimeLocal)
return;
}

if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?$/', $dateTimeLocal, $matches)) {
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?(?:\.\d)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?$/', $dateTimeLocal, $matches)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be possible to also support timezone without ":"?
if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})[T ]\d{2}:\d{2}(?::\d{2})?(?:\.\d)?(?:Z|(?:(?:\+|-)\d{2}:\d{2})|(?:\+|-)\d{4})?$/', $dateTimeLocal, $matches)) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you give an example string of what you have in mind so I can add it to the tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

2018-09-15T10:00:00+0200

Copy link
Member Author

Choose a reason for hiding this comment

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

done, thank you for the feedback

Technically, dates formatted according to the HTML specifications do not
contain any timezone information. But since our DateTimeType used to
contain this information in the passed, users had configure their JS
libraries to accept (and create) dates in that format.

To not break BC we should accept these dates and silently ignore the
additional timezone information.
Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!
Shouldn't we deprecate this behavior in master to be able to use a strict check in Symfony 5?

@magnetik
Copy link
Contributor

magnetik commented Oct 4, 2018

+1 for being clearer about what should work and not to be able to be stricter in the future

@xabbuh
Copy link
Member Author

xabbuh commented Oct 4, 2018

@HeahDude Yeah, I am already preparing some PRs to improve DX around this.

@xabbuh
Copy link
Member Author

xabbuh commented Oct 4, 2018

@HeahDude see #28724

@danrot
Copy link
Contributor

danrot commented Oct 4, 2018

@xabbuh Do you already know if this will be accepted? Because if it is not we have to fix our JS, otherwise we would only have to add this version as conflict, and we could release a new working version immediately.

@xabbuh
Copy link
Member Author

xabbuh commented Oct 4, 2018

@danrot Adding the conflict rule will be enough.

@danrot
Copy link
Contributor

danrot commented Oct 10, 2018

I've added the conflict for symfony 3.4.16 and 3.4.17 in our composer.json, but if you don't set our latest version (1.6.22) as minimum in the project composer.json, composer will install Sulu 1.6.21, so that it can use Symfony 3.4.17, which then still breaks the installation (hope you understand what I mean, otherwise I can elaborate further 🙈).

So people are really struggling with the installation of our product... Is there any other thing we can do, apart from kindly asking you to get this merged and release it? 😊

@YetiCGN
Copy link

YetiCGN commented Oct 10, 2018

I've added the conflict for symfony 3.4.16 and 3.4.17 in our composer.json, but if you don't set our latest version (1.6.22) as minimum in the project composer.json, composer will install Sulu 1.6.21, so that it can use Symfony 3.4.17, which then still breaks the installation (hope you understand what I mean, otherwise I can elaborate further 🙈).

Huh? I have "sulu/sulu": "~1.6.0", as a dependency in several projects (all of our Sulu projects, actually) and composer update correctly installs Sulu 1.6.22. The only time this would fail is if people did the update last week when Sulu 1.6.22 wasn't out yet but Symfony 3.4.17 was already - like we did. But even then an Update after the release of Sulu 1.6.22 fixed it. Why would you think people are locked to Sulu 1.6.21?

@danrot
Copy link
Contributor

danrot commented Oct 10, 2018

Just tested it again, had a project with "sulu/sulu": "~1.6.22", where 1.6.22 was installed, no surpirse so far. Then I changed my composer.json in the following way (I assume that's what most Sulu users have in their composer.json):

-        "sulu/sulu": "~1.6.22",
+        "sulu/sulu": "~1.6.0",

Then I executed another composer update, and that's the output:

daniel@macbook ~/D/s/sulu-standard $ composer update
Loading composer repositories with package information                                                                                                                                                             
Updating dependencies (including require-dev)                                                                                                                                                                      
Package operations: 0 installs, 3 updates, 0 removals                                                                                                                                                              
  - Updating symfony/symfony (v3.4.15 => v3.4.17): Loading from cache                                                                                                                                              
  - Downgrading sulu/sulu (1.6.22 => 1.6.21):  Checking out c0c04cd95e                                                                                                                                             
  - Updating dantleech/phpcr-migrations-bundle (1.0.0 => 1.1.0): Loading from cache

In addition to that composer even tells me that Symfony is the reason for not installing 1.6.22:

daniel@macbook ~/D/s/sulu-standard $ composer why-not sulu/sulu 1.6.22
sulu/sulu  1.6.22  conflicts  symfony/symfony (2.8.10 || 3.4.12 || 3.4.16 || 3.4.17)

Just realized that it works, if the "sulu/sulu" require is before the "symfony/symfony" require 😕 Feels a bit weird, but we can't fix that for existing projects 😞

@YetiCGN
Copy link

YetiCGN commented Oct 10, 2018

Just realized that it works, if the "sulu/sulu" require is before the "symfony/symfony" require 😕 Feels a bit weird, but we can't fix that for existing projects 😞

Ah! See, we have "config": { "sort-packages": true }, in all our projects, which puts Sulu before Symfony. 🙂

@danrot
Copy link
Contributor

danrot commented Oct 10, 2018

And since sort-packages will be the default with symfony flex, that doesn't make me feel more comfortable 🙈 That means that if we have a conflict with a package that is ordered after sulu alphabetically there is no way to fix this 😕

@YetiCGN
Copy link

YetiCGN commented Oct 10, 2018

Anyhow, please somebody merge this to the LTS branches 2.8 and 3.4 so we can safely rely on backwards compatibility again. 🙂

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit 503239f into symfony:2.8 Oct 14, 2018
nicolas-grekas added a commit that referenced this pull request Oct 14, 2018
This PR was merged into the 2.8 branch.

Discussion
----------

[Form] reverse transform RFC 3339 formatted dates

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28699
| License       | MIT
| Doc PR        |

Technically, dates formatted according to the HTML specifications do not
contain any timezone information. But since our DateTimeType used to
contain this information in the passed, users had configure their JS
libraries to accept (and create) dates in that format.

To not break BC we should accept these dates and silently ignore the
additional timezone information.

Commits
-------

503239f reverse transform RFC 3339 formatted dates
@xabbuh xabbuh deleted the issue-28699-html5 branch October 14, 2018 18:37
This was referenced Nov 3, 2018
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.

None yet

8 participants