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

[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 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.4frommaidmaid:vardumper-period
Aug 29, 2017

Conversation

maidmaid
Copy link
Contributor

@maidmaidmaidmaid commentedJul 25, 2017
edited
Loading

QA
Branch?3.4
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#23591 (comment)
LicenseMIT
Doc PR/

Result:

@maidmaid
Copy link
ContributorAuthor

maidmaid commentedJul 25, 2017
edited
Loading

First proposal:

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

@maidmaidmaidmaid changed the title[VarDumper] Add period caster[WIP] [VarDumper] Add period casterJul 25, 2017
@maidmaidmaidmaidforce-pushed thevardumper-period branch 2 times, most recently from4c9a9ee tocce0530CompareJuly 25, 2017 21:34
@nicolas-grekasnicolas-grekas added this to the3.4 milestoneJul 26, 2017
@ro0NL
Copy link
Contributor

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 commentedJul 26, 2017
edited
Loading

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

@maidmaidmaidmaidforce-pushed thevardumper-period branch 8 times, most recently froma22f12d to0f377e5CompareJuly 27, 2017 17:33
@maidmaid
Copy link
ContributorAuthor

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:002) 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?

@maidmaidmaidmaid changed the title[WIP] [VarDumper] Add period caster[VarDumper] Add period casterJul 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
ContributorAuthor

Choose a reason for hiding this comment

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

Limit tox 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
ContributorAuthor

@maidmaidmaidmaidAug 3, 2017
edited
Loading

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?

maidmaid reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Updated

@maidmaid
Copy link
ContributorAuthor

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 aboutx more (see iterator_count)

Copy link
ContributorAuthor

@maidmaidmaidmaidAug 6, 2017
edited
Loading

Choose a reason for hiding this comment

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

Yes, good idea. Butiterator_count() loops on all dates, what we want to avoid. We can findx withrecurrences - limit in recurrences case and(end - start - limit) / interval in date case. WDYT?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I addedx more ;) I comparediterator_count() and my method with 1M of reccurences:

  • 4160.1 ms withiterator_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

@ro0NLro0NLAug 6, 2017
edited
Loading

Choose a reason for hiding this comment

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

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

Copy link
ContributorAuthor

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)));

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
ContributorAuthor

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

@robfrawleyrobfrawleyAug 15, 2017
edited
Loading

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?

@maidmaidmaidmaidforce-pushed thevardumper-period branch 2 times, most recently from84f73dd to915fd4aCompareAugust 7, 2017 11:20
@maidmaid
Copy link
ContributorAuthor

Can you review this PR please? :)

@nicolas-grekas
Copy link
Member

is the screenshot up to date?

@maidmaid
Copy link
ContributorAuthor

Screenshot updated in PR description.

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

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
ContributorAuthor

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.

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) {

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
ContributorAuthor

Choose a reason for hiding this comment

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

getStartDate(),getDateInterval() andgetEndDate() 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) {

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

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

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
ContributorAuthor

Changes done + screenshot updated.

@nicolas-grekas
Copy link
Member

Thank you@maidmaid.

@nicolas-grekasnicolas-grekas merged commit4c4c398 intosymfony:3.4Aug 29, 2017
nicolas-grekas added a commit that referenced this pull requestAug 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, seehttps://travis-ci.org/symfony/symfony/jobs/269610022
Can you submit a fix please?

@maidmaid
Copy link
ContributorAuthor

Ok, I check that now.

@maidmaidmaidmaid deleted the vardumper-period branchAugust 29, 2017 15:32
nicolas-grekas added a commit that referenced this pull requestAug 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#v565Commits-------d84e9c8 Fix segfault in period caster
nicolas-grekas added a commit that referenced this pull requestAug 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 referencedOct 18, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@robfrawleyrobfrawleyrobfrawley left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@ro0NLro0NLro0NL approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
3.4
Development

Successfully merging this pull request may close these issues.

5 participants
@maidmaid@ro0NL@nicolas-grekas@robfrawley@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp