8000 [Console] Improve the helpfulness of %remaining% in Progress Bar · Issue #49927 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Console] Improve the helpfulness of %remaining% in Progress Bar #49927
Closed
@robjbrain

Description

@robjbrain

Description

At present the remaining time on the progress bar is not that helpful. If the remaining time is between 24 and 47 hours it will just read "1 days remaining".

Similarly if the time remaining is 1 hour 55 minutes, the text will actually display "1 hour remaining".

Obviously this isn't that helpful when planning around a process finishing.

In all my projects I now add this:

ProgressBar::setPlaceholderFormatterDefinition('remaining', function($bar) {
            $remaining = $bar->getRemaining();
            $hours = floor($remaining / 3600);
            $minutes = floor(($remaining / 60) % 60);
            $seconds = $remaining % 60;
            return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
        });

With this, when using the format: %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% taken %remaining:-6s% remaining, I will get the following:

This: 5/169200 [>---------------------------] 0% 5 secs taken 46:59:55 remaining

Instead of this: 5/169200 [>---------------------------] 0% 5 secs taken 1 day remaining

Or in the case of a 1 hour 48 minute process:

This: 5/6500 [>---------------------------] 0% 5 secs taken 01:48:15 remaining

Instead of this: 5/6500 [>---------------------------] 0% 5 secs taken 1 hr remaining

This could be implemented by updating Symfony\Component\Console\Helper

https://github.com/symfony/console/blob/3582d68a64a86ec25240aaa521ec8bc2342b369b/Helper/Helper.php#L91

To use the same logic as above. Although this would have the side effect of changing all dates. So it would in fact look like this:

5/6500 [>---------------------------] 0% 00:00:05 taken 01:48:15 remaining

I don't have an issue with that, but perhaps it's not desired?

I can create a PR if this is okay, but i've never contributed to Symfony before so figured I would start by creating an issue.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0