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 period caster #23668

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
Aug 29, 2017
Merged

Conversation

maidmaid
Copy link
Contributor

@maidmaid maidmaid commented Jul 25, 2017

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:

@maidmaid
Copy link
Contributor Author

maidmaid commented Jul 25, 2017

First proposal:

screenshot from 2017-07-25 20-48-58

@maidmaid maidmaid changed the title [VarDumper] Add period caster [WIP] [VarDumper] Add period caster Jul 25, 2017
@maidmaid maidmaid force-pushed the vardumper-period branch 2 times, most recently from 4c9a9ee to cce0530 Compare July 25, 2017 21:34
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jul 26, 2017
@ro0NL
Copy link
Contributor

ro0NL commented Jul 26, 2017

If we only want start/end/interval to be nicely dumped, that would already work as is right?

Im not sure about the fancy period formatting :) though i like your creativity 👍

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 26, 2017

agree with @ro0NL, not really convinced myself sorry...
maybe something like "every $period from $start to $end" (& variants)?

@maidmaid maidmaid force-pushed the vardumper-period branch 8 times, most recently from a22f12d to 0f377e5 Compare July 27, 2017 17:33
@maidmaid
Copy link
Contributor Author

Ok, I made tests green and I updated format. Example with end date (1) and with recurrences (2):

1) every + 1d, from 2017-01-01 00:00:00 (included) to 2017-01-03 00:00:00
2) every + 1d, from 2017-01-01 00:00:00 (included) for 2x

I kept tooltip with the dates included in the period. I find this useful, and you?

@maidmaid maidmaid changed the title [WIP] [VarDumper] Add period caster [VarDumper] Add period caster Jul 27, 2017
if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639
$format = 'Y-m-d'.('000000' === $p->getStartDate()->format('His') && '000' === $p->getDateInterval()->format('%h%i%s') ? '' : ' H:i:s');
foreach (clone $p as $i => $d) {
$dates[] = sprintf('%s) %s', $i + 1, $d->format($format));
Copy link
Contributor

Choose a reason for hiding this comment

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

this list can become insanely long... not sure we should do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Limit to x first items would be better? If yes, showing the first 12 items seem good 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.

dunno.. i would leave it out and keep the virtual period property.

Copy link
Contributor Author

@maidmaid maidmaid Aug 3, 2017

Choose a reason for hiding this comment

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

Mmh, an overview of dates period can be very useful I think. Let's wait for other opinions ;)

self::formatInterval($p->getDateInterval()),
$p->getStartDate()->format('Y-m-d H:i:s'),
$p->include_start_date ? 'included' : 'excluded',
($end = $p->getEndDate()) ? 'to '.$end->format('Y-m-d H:i:s') : 'for '.$p->recurrences.'x'
Copy link
Contributor

Choose a reason for hiding this comment

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

, recurring x time/s?

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

@maidmaid
Copy link
Contributor Author

maidmaid commented Aug 3, 2017

Fail not related.

foreach (clone $p as $i => $d) {
$dates[] = sprintf('%s) %s', $i + 1, $d->format('Y-m-d H:i:s'));
if (11 === $i) {
$dates[] = '...';
Copy link
Contributor

Choose a reason for hiding this comment

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

what about x more (see iterator_count)

Copy link
Contributor Author

@maidmaid maidmaid Aug 6, 2017

Choose a reason for hiding this comment

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

Yes, good idea. But iterator_count() loops on all dates, what we want to avoid. We can find x with recurrences - limit in recurrences case and (end - start - limit) / interval in date case. WDYT?

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 added x more ;) I compared iterator_count() and my method with 1M of reccurences:

  • 4160.1 ms with iterator_count()
  • 0.1 ms with my method

self::formatInterval($p->getDateInterval()),
$p->getStartDate()->format('Y-m-d H:i:s'),
$p->include_start_date ? 'included' : 'excluded',
($end = $p->getEndDate()) ? 'to '.$end->format('Y-m-d H:i:s') : 'recurring '.$p->recurrences.' time/s'
Copy link
Contributor

@ro0NL ro0NL Aug 6, 2017

Choose a reason for hiding this comment

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

maybe add 1 === $p->recurrences ? 'recurring once' : ... case for time/s :)

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 don't see the interest of this. Always having a digital format is the simplest, no?

($end = $p->getEndDate()) ? 'to '.$end->format('Y-m-d H:i:s') : 'recurring '.$p->recurrences.' time/s'
);

$p = array(Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode(PHP_EOL, $dates)));
Copy link
Member

Choose a reason for hiding this comment

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

"\n" instead of PHP_EOL

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 (Why exactly do you ask this change?)

Copy link
Contributor

@robfrawley robfrawley Aug 15, 2017

Choose a reason for hiding this comment

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

Purely out of interest, I too would like to know why the change. Is it simply a Symfony convention or is there an another underlying reason for it?

@maidmaid maidmaid force-pushed the vardumper-period branch 2 times, most recently from 84f73dd to 915fd4a Compare August 7, 2017 11:20
@maidmaid
Copy link
Contributor Author

Can you review this PR please? :)

@nicolas-grekas
Copy link
Member

is the screenshot up to date?

@maidmaid
Copy link
Contributor Author

Screenshot updated in PR description.

@@ -20,6 +20,8 @@
*/
class DateCaster
{
const PERIOD_LIMIT = 12;
Copy link
Member

Choose a reason for hiding this comment

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

why 12? I would have set 3 myself :)
the const should be removed (as we cannot make it private)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's arbitrary but monthly periods can be displayed for a whole year with a limit of 12.

Copy link
Member

Choose a reason for hiding this comment

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

3 still looks enough to me, nobody will look at 12 values...

@@ -80,6 +82,41 @@ public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stu
return $filter & Caster::EXCLUDE_VERBOSE ? $z : $z + $a;
}

public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNested, $filter)
{
if (defined('HHVM_VERSION_ID') || \PHP_VERSION_ID < 50605) {
Copy link
Member

Choose a reason for hiding this comment

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

what happens before 5.6.5?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getStartDate(), getDateInterval() and getEndDate() methods were added in 5.6.5.

$dates = array();
if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639
foreach (clone $p as $i => $d) {
if (self::PERIOD_LIMIT === $i) {
Copy link
Member

Choose a reason for hiding this comment

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

if (3 === $i) {

$now = new \DateTimeImmutable();
$dates[] = sprintf('%s more', ($end = $p->getEndDate())
? ceil(($end->format('U.u') - $d->format('U.u')) / ($now->add($p->getDateInterval())->format('U.u') - $now->format('U.u')))
: $p->recurrences - self::PERIOD_LIMIT
Copy link
Member

Choose a reason for hiding this comment

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

$p->recurrences - $i

if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639
foreach (clone $p as $i => $d) {
if (self::PERIOD_LIMIT === $i) {
// avoids iterator_count() function which can be expensive
Copy link
Member

Choose a reason for hiding this comment

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

not sure about the comment: nobody was wondering about iterator_count until read :)

@maidmaid
Copy link
Contributor Author

Changes done + screenshot updated.

@nicolas-grekas
Copy link
Member

Thank you @maidmaid.

@nicolas-grekas nicolas-grekas merged commit 4c4c398 into symfony:3.4 Aug 29, 2017
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
@nicolas-grekas
Copy link
Member

@maidmaid this is segfaulting on PHP 5.6, see https://travis-ci.org/symfony/symfony/jobs/269610022
Can you submit a fix please?

@maidmaid
Copy link
Contributor Author

Ok, I check that now.

@maidmaid maidmaid deleted the vardumper-period branch August 29, 2017 15:32
nicolas-grekas added a commit that referenced this pull request Aug 29, 2017
This PR was merged into the 3.4 branch.

Discussion
----------

[VarDumper] Fix segfault in period caster

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

[This segfault](https://bugs.php.net/bug.php?id=71635) was fixed in [5.6.20](http://www.php.net/ChangeLog-5.php#5.6.20) and in [7.0.5](http://www.php.net/ChangeLog-7.php#7.0.5).

Issue in action here: https://3v4l.org/DhOdT#v565

Commits
-------

d84e9c8 Fix segfault in period caster
nicolas-grekas added a commit that referenced this pull request Aug 31, 2017
This PR was merged into the 4.0-dev branch.

Discussion
----------

[VarDumper] Prepare period caster for 4.0

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

Commits
-------

fd7352e Prepare period caster for 4.0
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.

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