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

[Console] Moved estimated & remaining calculation logic to separate get method #35611

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
Feb 10, 2020

Conversation

peterjaap
Copy link
Contributor

@peterjaap peterjaap commented Feb 6, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT

This way, we can use getEstimated()and getRemaining() to get easy access to the estimated / remaining number of seconds to be used in our placeholder definition set with setPlaceholderFormatterDefinition without having to redefine the calculation ourself.

Example before;

ProgressBar::setPlaceholderFormatterDefinition(
    'eta',
    function (ProgressBar $progressBar) {
        $estimated = round((time() - $progressBar->getStartTime()) / ($progressBar->getProgress() ?: 0.1) * $progressBar->getMaxSteps());
        return date('H:i:s', strtotime('+' . $estimated . ' seconds'));
    }
);

Example after;

ProgressBar::setPlaceholderFormatterDefinition(
    'eta',
    function (ProgressBar $progressBar) {
        return date('H:i:s', strtotime('+' . $this->getEstimated() . ' seconds'));
    }
);

@peterjaap peterjaap changed the title Moved estimated calculation logic to separate get method Moved estimated & remaining calculation logic to separate get method Feb 6, 2020
@nicolas-grekas nicolas-grekas added this to the next milestone Feb 6, 2020
@nicolas-grekas nicolas-grekas changed the title Moved estimated & remaining calculation logic to separate get method [Console] Moved estimated & remaining calculation logic to separate get method Feb 6, 2020
Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

Can you apply fabbot's patch?

@peterjaap
Copy link
Contributor Author

@fabpot done! :)

@nicolas-grekas
Copy link
Member

The failure in tests is relevant to the change proposed here.

@peterjaap
Copy link
Contributor Author

@nicolas-grekas done 🎉

src/Symfony/Component/Console/Helper/ProgressBar.php Outdated Show resolved Hide resolved
@fabpot
Copy link
Member

fabpot commented Feb 10, 2020

@peterjaap Can you rebase to get rid of the merge commit? Thank you.

@nicolas-grekas
Copy link
Member

Thank you @peterjaap.

nicolas-grekas added a commit that referenced this pull request Feb 10, 2020
…c to separate get method (peterjaap)

This PR was squashed before being merged into the 5.1-dev branch.

Discussion
----------

[Console] Moved estimated & remaining calculation logic to separate get method

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT

This way, we can use `getEstimated()`and `getRemaining()` to get easy access to the estimated / remaining number of seconds to be used in our placeholder definition set with `setPlaceholderFormatterDefinition` without having to redefine the calculation ourself.

Example before;

```php
ProgressBar::setPlaceholderFormatterDefinition(
    'eta',
    function (ProgressBar $progressBar) {
        $estimated = round((time() - $progressBar->getStartTime()) / ($progressBar->getProgress() ?: 0.1) * $progressBar->getMaxSteps());
        return date('H:i:s', strtotime('+' . $estimated . ' seconds'));
    }
);
```

Example after;

```php
ProgressBar::setPlaceholderFormatterDefinition(
    'eta',
    function (ProgressBar $progressBar) {
        return date('H:i:s', strtotime('+' . $this->getEstimated() . ' seconds'));
    }
);
```

Commits
-------

19958fb [Console] Moved estimated & remaining calculation logic to separate get method
@nicolas-grekas nicolas-grekas merged commit 19958fb into symfony:master Feb 10, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
@fabpot fabpot mentioned this pull request May 5, 2020
@peterjaap peterjaap deleted the patch-1 branch May 6, 2020 03:36
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.