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

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

Merged
merged 1 commit into from Feb 10, 2020

Conversation

@peterjaap
Copy link
Contributor

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
@fabpot
fabpot approved these changes Feb 7, 2020
Copy link
Member

fabpot left a comment

Can you apply fabbot's patch?

@peterjaap

This comment has been minimized.

Copy link
Contributor Author

peterjaap commented Feb 7, 2020

@fabpot done! :)

@nicolas-grekas

This comment has been minimized.

Copy link
Member

nicolas-grekas commented Feb 7, 2020

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

@peterjaap

This comment has been minimized.

Copy link
Contributor Author

peterjaap commented Feb 7, 2020

@nicolas-grekas done 🎉

@fabpot

This comment has been minimized.

Copy link
Member

fabpot commented Feb 10, 2020

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

@fabpot
fabpot approved these changes Feb 10, 2020
@nicolas-grekas nicolas-grekas force-pushed the peterjaap:patch-1 branch from 281361e to 19958fb Feb 10, 2020
@nicolas-grekas

This comment has been minimized.

Copy link
Member

nicolas-grekas commented Feb 10, 2020

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
1 of 3 checks passed
1 of 3 checks passed
continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
fabbot.io Your code looks good.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.