Skip to content

Instantly share code, notes, and snippets.

@robjbrain
Created April 4, 2023 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robjbrain/ae1f011473fc29b0151d0c3e2421572e to your computer and use it in GitHub Desktop.
Save robjbrain/ae1f011473fc29b0151d0c3e2421572e to your computer and use it in GitHub Desktop.
Improved remaining time calculation for laravel and symfony progress bar
//In order to get more accurate remaining time when using Laravel Progress Bar add this to AppServerProvider@boot
use Symfony\Component\Console\Helper\ProgressBar;
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);
});
// Here is an example of a progress bar which will take 1 hour and 48 minutes to complete:
// Before
// 5/6500 [>---------------------------] 0% 5 secs taken 1 hr remaining
// After
// 5/6500 [>---------------------------] 0% 5 secs taken 01:48:15 remaining
// As you can see it's much clearer, now you know you have nearly 2 hours to wait rather than wrongly thinking it will take 1 hour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment