Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Validator][ConstraintValidator] Safe fail on invalid timezones#34904

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:3.4fromfancyweb:validator-zulu-fix-
Dec 13, 2019

Conversation

fancyweb
Copy link
Contributor

Co-authored-by: Scott Dawsonscott@loyaltycorp.com.au

QA
Branch?3.4
Bug fix?yes
New feature?no
Deprecations?no
Tickets#33901
LicenseMIT
Doc PR

Alternative to#33902.

I will explain why I think it is better this way:

  1. We set the timezone with the setter because it's 100% safe, it never fails. It fall backs to the default timezone if the provided timezone is not supported (as if we passed null, so the same behavior that always existed). We are therefore compatible with all edge cases.
  2. We don't validate the timezone with\DateTimeZone::listIdentifiers(). It only returns full identifiers like "Europe/Paris" but it doesn't take into account "numeric" identifiers such as "+08:00" which are perfectly valid. I added a test case to ensure we stay valid with this case. + some invalid identifiers for the native\IntlDateFormatter are valid with the polyfill that uses\DateTimeZone (eg :X). I don't think we can validate anything safely that will work reliably on both implementations.

PandaaAgency reacted with thumbs up emoji
@fancyweb
Copy link
ContributorAuthor

Tests pass on my machine with both implem (polyfill and native) but fails on CI 😕 Looks like the good value is not returned when using UTC.

@ycerutoyceruto added this to the3.4 milestoneDec 9, 2019
@fancyweb
Copy link
ContributorAuthor

fancyweb commentedDec 9, 2019
edited
Loading

Also we have to think of what is the goal here: display the passed date relatively to its timezone (the same datetime in all timezones must display the same thing basically). Can't we just always set the formatter to UTC, copy the passed value in a temp var and set the timezone to UTC, so we don't have to deal with this timezone stuff?

@fancywebfancywebforce-pushed thevalidator-zulu-fix- branch 2 times, most recently from9871424 to7fbfa3cCompareDecember 10, 2019 07:55
@fancyweb
Copy link
ContributorAuthor

Can't we just always set the formatter to UTC, copy the passed value in a temp var and set the timezone to UTC, so we don't have to deal with this timezone stuff?

Looks like we can. It simplifies everything. I just pushed it.

@nicolas-grekas
Copy link
Member

rebase needed

Co-authored-by: Scott Dawson <scott@loyaltycorp.com.au>
@fancyweb
Copy link
ContributorAuthor

Rebased + tests pass. I modified the tests to strenghten them.

PandaaAgency reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

Thank you@fancyweb.

nicolas-grekas added a commit that referenced this pull requestDec 13, 2019
…zones (fancyweb)This PR was merged into the 3.4 branch.Discussion----------[Validator][ConstraintValidator] Safe fail on invalid timezonesCo-authored-by: Scott Dawson <scott@loyaltycorp.com.au>| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |#33901| License       | MIT| Doc PR        |Alternative to#33902.I will explain why I think it is better this way:1. We set the timezone with the setter because it's 100% safe, it never fails. It fall backs to the default timezone if the provided timezone is not supported (as if we passed null, so the same behavior that always existed). We are therefore compatible with all edge cases.2. We don't validate the timezone with `\DateTimeZone::listIdentifiers()`. It only returns full identifiers like "Europe/Paris" but it doesn't take into account "numeric" identifiers such as "+08:00" which are perfectly valid. I added a test case to ensure we stay valid with this case. + some invalid identifiers for the native `\IntlDateFormatter` are valid with the polyfill that uses `\DateTimeZone` (eg : `X`). I don't think we can validate anything safely that will work reliably on both implementations.Commits-------3b1b994 [Validator][ConstraintValidator] Safe fail on invalid timezones
@nicolas-grekasnicolas-grekas merged commit3b1b994 intosymfony:3.4Dec 13, 2019
@fancywebfancyweb deleted the validator-zulu-fix- branchDecember 19, 2019 12:08
This was referencedDec 19, 2019
This was referencedJan 21, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
3.4
Development

Successfully merging this pull request may close these issues.

4 participants
@fancyweb@nicolas-grekas@yceruto@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp