-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] Add date caster #22431
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
Conversation
/cc @nicolas-grekas |
Btw.. about the timezone. What about putting the offset in front? this is the part i usually care about...
|
$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'), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Not sure.. it looks a bit more chaotic imo (less raw). Compared to the first proposal, i think we should go with |
Now, |
* | ||
* @author Dany Maillard <danymaillard93b@gmail.com> | ||
*/ | ||
class DateCaster |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why waiting?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
@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). |
@robfrawley Yes, unix time can be usefull, but it's a machine format and we should favor human representation, IMO. |
@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) |
We have lots of different interesting opinions. @nicolas-grekas, can you give your opinion? |
May I propose something different: |
But works it with |
CliDumper would display only |
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.) |
When we var_dump a |
worth a try yes :) |
Personally, I like compact formats, that give me everything in a snap. |
What about displaying the timestamp next to the class name |
"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') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
Do you like it? I think I do :)
in fact, that's not true: |
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 |
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. |
Shouldn't the 'from now' be 'from server time' , using 'now' can be confusing if the server time is not the developer time WDYT ? |
@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. |
@nicolas-grekas I think this version is quite conclusive. What about merge this and open new PR if we have tweaks? |
There was a problem hiding this 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)
13250cd
to
2b00e4e
Compare
This should be ready to be merged now :) |
If we want to support DateInterval, I think it should be done in this PR. |
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 ;) BTW, I agree with the comment on the name of the caster method: should be |
Ok, I removed DateInterval caster and I renamed caster method to |
Thank you @maidmaid. |
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
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
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
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
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: