@@ -191,11 +191,29 @@ public function getProgressPercent(): float
191
191
return $ this ->percent ;
192
192
}
193
193
194
- public function getBarOffset (): int
194
+ public function getBarOffset (): float
195
195
{
196
196
return floor ($ this ->max ? $ this ->percent * $ this ->barWidth : (null === $ this ->redrawFreq ? min (5 , $ this ->barWidth / 15 ) * $ this ->writeCount : $ this ->step ) % $ this ->barWidth );
197
197
}
198
198
199
+ public function getEstimated (): float
200
+ {
201
+ if (!$ this ->step ) {
202
+ return 0 ;
203
+ }
204
+
205
+ return round ((time () - $ this ->startTime ) / $ this ->step * $ this ->max );
206
+ }
207
+
208
+ public function getRemaining (): float
209
+ {
210
+ if (!$ this ->step ) {
211
+ return 0 ;
212
+ }
213
+
214
+ return round ((time () - $ this ->startTime ) / $ this ->step * ($ this ->max - $ this ->step ));
215
+ }
216
+
199
217
public function setBarWidth (int $ size )
200
218
{
201
219
$ this ->barWidth = max (1 , $ size );
@@ -500,26 +518,14 @@ private static function initPlaceholderFormatters(): array
500
518
throw new LogicException ('Unable to display the remaining time if the maximum number of steps is not set. ' );
501
519
}
502
520
503
- if (!$ bar ->getProgress ()) {
504
- $ remaining = 0 ;
505
- } else {
506
- $ remaining = round ((time () - $ bar ->getStartTime ()) / $ bar ->getProgress () * ($ bar ->getMaxSteps () - $ bar ->getProgress ()));
507
- }
508
-
509
- return Helper::formatTime ($ remaining );
521
+ return Helper::formatTime ($ bar ->getRemaining ());
510
522
},
511
523
'estimated ' => function (self $ bar ) {
512
524
if (!$ bar ->getMaxSteps ()) {
513
525
throw new LogicException ('Unable to display the estimated time if the maximum number of steps is not set. ' );
514
526
}
515
527
516
- if (!$ bar ->getProgress ()) {
517
- $ estimated = 0 ;
518
- } else {
519
- $ estimated = round ((time () - $ bar ->getStartTime ()) / $ bar ->getProgress () * $ bar ->getMaxSteps ());
520
- }
521
-
522
- return Helper::formatTime ($ estimated );
528
+ return Helper::formatTime ($ bar ->getEstimated ());
523
529
},
524
530
'memory ' => function (self $ bar ) {
525
531
return Helper::formatMemory (memory_get_usage (true ));
0 commit comments