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

[VarDumper] Add date caster #22431

Merged
merged 1 commit into from Jul 3, 2017
Merged

Conversation

maidmaid
Copy link
Contributor

@maidmaid maidmaid commented Apr 14, 2017

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

I propose to add a DateCaster that casts date (with timestamp, date, time, timezone (offset + id), literal date, delta from now and DST) and interval.

Todo:

  • cast date
  • cast interval
  • add tests

@fabpot
Copy link
Member

fabpot commented Apr 14, 2017

/cc @nicolas-grekas

@ro0NL
Copy link
Contributor

ro0NL commented Apr 14, 2017

Btw.. about the timezone. What about putting the offset in front? this is the part i usually care about...

timezone: '+02:00 (Europe/Amsterdam)'

$prefix.'literal' => $d->format('l, j M Y'),
$prefix.'timestamp' => $d->getTimestamp(),
$prefix.'timezone' => $d->format('P (e)'),
$prefix.'Δnow' => (new DateTime())->diff($d)->format('%R %yy %mm %dd %H:%I:%S'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a setTimezone($d->getTimezone()) right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@maidmaid
Copy link
Contributor Author

screenshot from 2017-04-14 22-30-46
WDYT of this variant?

@ro0NL
Copy link
Contributor

ro0NL commented Apr 16, 2017

Not sure.. it looks a bit more chaotic imo (less raw).

Compared to the first proposal, i think we should go with datetime, timezone, Δnow as a bare minimum. Ie. i could do without literal and timestamp.

@maidmaid
Copy link
Contributor Author

maidmaid commented Apr 30, 2017

Now, literal and timestamp are not visible if they are nested or if we flag with EXCLUDE_VERBOSE. I have too add tests.

*
* @author Dany Maillard <danymaillard93b@gmail.com>
*/
class DateCaster
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 named DateTimeCaster IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a next PR, I would cast other date classes like DateInterval. It's why a generic DateCaster is better IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

why waiting?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, it would be better to have everything in the same PR.

namespace Symfony\Component\VarDumper\Caster;

use DateTime;
use DateTimeInterface;
Copy link
Member

Choose a reason for hiding this comment

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

We never add use statements for global classes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@robfrawley
Copy link
Contributor

@maidmaid I was a fan of the first proposal. The unix time is almost always the most important field to me (though this could depend on the operating system one uses, I guess).

@maidmaid
Copy link
Contributor Author

maidmaid commented May 1, 2017

@robfrawley Yes, unix time can be usefull, but it's a machine format and we should favor human representation, IMO.

@ogizanagi
Copy link
Member

ogizanagi commented May 1, 2017

@maidmaid : It depends on the situation, but you might be happy to have the unix time while debugging. And I'm mainly using the var-dumper component for debugging purpose 😄 (I'd say I rather have the timestamp than the delta or literal version)

@maidmaid
Copy link
Contributor Author

maidmaid commented May 1, 2017

We have lots of different interesting opinions. @nicolas-grekas, can you give your opinion?

@nicolas-grekas
Copy link
Member

May I propose something different:
always display a single line that represents 100% of the state of the objects: 'Y-m-d H:i:s.u e'
then lets provide more details on hover (... from now, literal, etc as a single "title" line).
This is doable with a single virtual propery holding a ConstStub I think.

@maidmaid
Copy link
Contributor Author

maidmaid commented May 2, 2017

then lets provide more details on hover

But works it with CliDumper?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 2, 2017

CliDumper would display only Y-m-d H:i:s.u e, but this LGTM, that's still 100% of the state.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 2, 2017

For the reader: when I saw that, I first thought "hey, this is hiding the actual internal structure of DateTime objects" (by not telling about these existing public props.)
Then I ran this: https://3v4l.org/uWc54
It looks like doing var_dump/array-cast actually creates the 3 props...
So I'm even more in favor of doing something here, and I would add DateTimeZone, etc. to the list of classes that should display only virtual props.

@maidmaid
Copy link
Contributor Author

maidmaid commented May 2, 2017

When we var_dump a DateTime object, we can see 3 props in all but 2 distinct props: date and timezone. So, DateCaster should cast a date prop that represents 100% of date/time infos (with more details on hover), and a timezone prop that shows a DateTimeZone thanks to an other caster (that is already in WIP here). Right?

@nicolas-grekas
Copy link
Member

worth a try yes :)

@maidmaid
Copy link
Contributor Author

maidmaid commented May 2, 2017

As discussed:

screenshot from 2017-05-02 13-40-00

My remarks: too bad it is not possible to copy timestamp and to see extra info in CLI with this version. More, I find it strange to use ConstStub to show extra in hover, it seems as a hack.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 2, 2017

Personally, I like compact formats, that give me everything in a snap.
I would also remove the timezone prop in fact, and add the "e" placeholder at the end of the date string.
Nesting is an opportunity to be hit by depth limiting, better not.
Copy/pasting the timestamp looks like something I wouldn't do very often to me (especially since it's destructive compared to a DateTime object).
Of course, that's only my personal PoV :)

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 2, 2017

What about displaying the timestamp next to the class name DateTime @123456789 { ... }? Should be just a matter of appending it to the $stub->class prop.

"literal: %s\ntimestamp: %s\nΔnow: %s",
$d->format('l, j F Y'),
$d->getTimestamp(),
(new \DateTime('now', $d->getTimezone()))->diff($d)->format('%R %yy %mm %dd %H:%I:%S')
Copy link
Member

Choose a reason for hiding this comment

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

$d->getTimezone() is not required in this context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@maidmaid
Copy link
Contributor Author

maidmaid commented May 2, 2017

I putted timestamp in $stub->class and displayed timezone in date virtual prop (used P instead e because +02:00 is more informative that Europe/Zurich):

screenshot from 2017-05-02 15-56-31

@nicolas-grekas
Copy link
Member

Do you like it? I think I do :)

used P instead e because +02:00 is more informative

in fact, that's not true: Europe/Zurich contains geographical/political info that makes it very different from +02:00.
See http://stackoverflow.com/questions/17694894/different-timezone-types-on-datetime-object

@maidmaid
Copy link
Contributor Author

maidmaid commented May 2, 2017

Yes, I find this version quite elegant :)

About timezone, I think that we have to know difference to GMT when we debug a date but not its geographical/political infos. Are you agree?

My only little remark rests on ConstStub hack usage to showing extra infos when [ConstStub] Represents a PHP constant and its value.

@maidmaid
Copy link
Contributor Author

maidmaid commented May 8, 2017

More, the plus-value of literal format is to show day of week and textual month. With U.S. standard, these 2 items are in the front.

@FabienPapet
Copy link

Shouldn't the 'from now' be 'from server time' , using 'now' can be confusing if the server time is not the developer time

WDYT ?

@maidmaid
Copy link
Contributor Author

maidmaid commented May 8, 2017

@FabienPapet I think that dump a date is in most cases a debug step that is realized on our local machine whose time we known.

@maidmaid
Copy link
Contributor Author

maidmaid commented May 8, 2017

@nicolas-grekas I think this version is quite conclusive. What about merge this and open new PR if we have tweaks?

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍 (To be merged when the feature freeze is over)

@ogizanagi
Copy link
Member

This should be ready to be merged now :)

@nicolas-grekas nicolas-grekas self-assigned this Jun 26, 2017
@fabpot
Copy link
Member

fabpot commented Jun 28, 2017

If we want to support DateInterval, I think it should be done in this PR.

@maidmaid
Copy link
Contributor Author

Ok, I added DateInterval caster.

Before After
screenshot from 2017-06-28 14-17-40 screenshot from 2017-06-28 14-17-54

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 3, 2017

Hum, let's remove the DateInterval caster, at least from this PR. The issue I have is accuracy and teaching. Dump should be informational about how things actually works or can be used. On a DateInterval, the listed values are actual public properties. VarDumper is about showing actual facts about objects, not alternate ones ;)
The concern does not exist with DateTime objects because there is no properties there.

BTW, I agree with the comment on the name of the caster method: should be castDateTime also IMHO.

@maidmaid
Copy link
Contributor Author

maidmaid commented Jul 3, 2017

Ok, I removed DateInterval caster and I renamed caster method to castDateTime.

@nicolas-grekas
Copy link
Member

Thank you @maidmaid.

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

Discussion
----------

[VarDumper] Add date caster

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

I propose to add a ``DateCaster`` that casts date (with timestamp, date, time, timezone (offset + id), literal date, delta from now and DST) and interval.

Todo:
- [x] cast date
- [x] cast interval
- [x] add tests

Commits
-------

1dbdf1c Add DateCaster
@maidmaid maidmaid deleted the datecaster branch July 3, 2017 08:51
nicolas-grekas added a commit that referenced this pull request Jul 19, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[VarDumper] Add interval caster

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

 cf #22431 (comment)

Commits
-------

a73522c Add interval caster
symfony-splitter pushed a commit to symfony/var-dumper that referenced this pull request Jul 19, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[VarDumper] Add interval caster

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

 cf symfony/symfony#22431 (comment)

Commits
-------

a73522c Add interval caster
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
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.

None yet

10 participants