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

[VarDumper] Add time zone caster #23591

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

Merged
merged 1 commit into from
Jul 21, 2017
Merged

Conversation

maidmaid
Copy link
Contributor

@maidmaid maidmaid commented Jul 19, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #22431 (comment)
License MIT
Doc PR /

@maidmaid
Copy link
Contributor Author

Proposal (exlude verbose mode):

screenshot from 2017-07-19 15-31-17

@maidmaid maidmaid force-pushed the vardumper-tz branch 2 times, most recently from 76fae7d to 4d37445 Compare July 19, 2017 14:05
Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

cool 👍

@@ -28,7 +28,8 @@
},
"suggest": {
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).",
"ext-symfony_debug": ""
"ext-symfony_debug": "",
"ext-inlt": "To show region in time zone dump"
Copy link
Contributor

Choose a reason for hiding this comment

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

ext-intl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, fixed ;)

@@ -32,7 +32,7 @@ public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub,
;

$a = array();
$a[$prefix.'date'] = new ConstStub($d->format('Y-m-d H:i:s.u '.($location ? 'e (P)' : 'P')), $title);
$a[$prefix.'date'] = new ConstStub($d->format('Y-m-d H:i:s.u ').self::formatTimeZone($d->getTimezone()), $title);
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps inline $location above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@maidmaid maidmaid force-pushed the vardumper-tz branch 3 times, most recently from 132df43 to 27bf394 Compare July 19, 2017 14:25
@nicolas-grekas
Copy link
Member

(but tests are red)

@ro0NL
Copy link
Contributor

ro0NL commented Jul 19, 2017

hhvm being weird :) Locale::getDisplayRegion() expects exactly 2 parameters, 1 given

@maidmaid
Copy link
Contributor Author

I hate you hhvm! I add a 2nd null arg.

@ro0NL
Copy link
Contributor

ro0NL commented Jul 19, 2017

Agree :) this is insane.

I believe windows was failing due missing intl =/ lets see :)

@maidmaid
Copy link
Contributor Author

On AppVeyor, Intl component takes over and this throws an exception. How fix this?

@ro0NL
Copy link
Contributor

ro0NL commented Jul 19, 2017

try/catch it? Ideally it would be implemented for en locale i guess.

if (($location = $timeZone->getLocation()) && method_exists('\Locale', 'getDisplayRegion')) {
try {
$title = \Locale::getDisplayRegion('-'.$location['country_code'], null);
} catch (\Exception $e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd catch Symfony\Component\Intl\Exception\MethodNotImplementedException explicitly here. Anything else should trow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I finally handled this with extension_loaded('intl') but I'm not sure. Is it good for you?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good 👍

@@ -111,6 +111,7 @@

'DateTimeInterface' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castDateTime'),
'DateInterval' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castInterval'),
'DateTimeZone' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Im assuming next is DatePeriod for completion? That can be easily wired now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! But let's first fully agree on time zone 😅

@@ -28,7 +28,8 @@
},
"suggest": {
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).",
"ext-symfony_debug": ""
"ext-symfony_debug": "",
"ext-intl": "To show region in time zone dump"
Copy link
Contributor

@ro0NL ro0NL Jul 19, 2017

Choose a reason for hiding this comment

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

To show region name in a time zone dump?

Also perhaps move 1 line up.

$title = '';
if (($location = $timeZone->getLocation()) && method_exists('\Locale', 'getDisplayRegion')) {
try {
$title = \Locale::getDisplayRegion('-'.$location['country_code'], null);
Copy link
Contributor

Choose a reason for hiding this comment

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

null => \Locale::getDefault() that be safest

see https://3v4l.org/eAigW

@maidmaid maidmaid force-pushed the vardumper-tz branch 2 times, most recently from 0d2ad57 to 7f97d70 Compare July 20, 2017 07:46
@maidmaid
Copy link
Contributor Author

Tests are green :)


private static function formatTimeZone(\DateTimeZone $z)
{
return (new \Datetime('now', $z))->format($z->getLocation() ? 'e (P)' : 'P');
Copy link
Member

Choose a reason for hiding this comment

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

this method should be removed, it forces repeated calls to getLocation that inlinfing prevented - I'm sure things will be easier to read when removed. That means all changes on the castDateTime method should be reverted to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated


public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stub, $isNested, $filter)
{
$title = ($location = $timeZone->getLocation()) && extension_loaded('intl')
Copy link
Member

Choose a reason for hiding this comment

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

$location on its own line + $title on a single line would be better imho

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated (although this line is a bit long now...)

@maidmaid
Copy link
Contributor Author

Time to merge?

{
$location = $timeZone->getLocation();
$formatted = (new \Datetime('now', $timeZone))->format($location ? 'e (P)' : 'P');
$title = $location && extension_loaded('intl') ? \Locale::getDisplayRegion('-'.$location['country_code'], \Locale::getDefault()) : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

just realized, does it make sense to use Locale::getDefault() instead of just en. Not sure this output needs to be localized at all 😕

Copy link
Member

Choose a reason for hiding this comment

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

dump output is already locale sensitive, so this makes sense to me

Copy link
Contributor

Choose a reason for hiding this comment

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

date format in castDateTime is not.. which made me think this should follow.

No blocker for me or so :)

@nicolas-grekas
Copy link
Member

Thank you @maidmaid.

@nicolas-grekas nicolas-grekas merged commit 5c4bfac into symfony:3.4 Jul 21, 2017
nicolas-grekas added a commit that referenced this pull request Jul 21, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[VarDumper] Add time zone caster

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22431 (comment)
| License       | MIT
| Doc PR        | /

Commits
-------

5c4bfac Add time zone caster
@maidmaid maidmaid deleted the vardumper-tz branch July 21, 2017 13:45
nicolas-grekas added a commit that referenced this pull request Aug 29, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[VarDumper] Add period caster

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23591 (comment)
| License       | MIT
| Doc PR        | /

Result:

![](https://user-images.githubusercontent.com/4578773/29788181-fce3eb32-8c31-11e7-9da4-72c038d5a14e.png)

Commits
-------

4c4c398 Add period caster
symfony-splitter pushed a commit to symfony/var-dumper that referenced this pull request Aug 29, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[VarDumper] Add period caster

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony#23591 (comment)
| License       | MIT
| Doc PR        | /

Result:

![](https://user-images.githubusercontent.com/4578773/29788181-fce3eb32-8c31-11e7-9da4-72c038d5a14e.png)

Commits
-------

4c4c398 Add period caster
This was referenced Oct 18, 2017
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.

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