@@ -160,46 +160,32 @@ function extimatedTimeLeft(float $startmicrotime, float $taskCurrentIteration, f
160
160
/**
161
161
* Transforms the number of $seconds into minutes, hours and days if needed providing a better human-readable string
162
162
* @param float $seconds
163
- * @param bool $zeropad
164
163
* @return string
165
164
*/
166
- function secondsToHumanTime (float $ seconds, bool $ zeropad = false ): string
165
+ function secondsToHumanTime (float $ seconds ): string
167
166
{
168
- $ padder = fn (float $ item , int $ length ) => str_pad ((string ) $ item , $ length , $ zeropad ? '0 ' : ' ' , STR_PAD_LEFT );
167
+ static $ padder = null ;
168
+ $ padder ??= fn (float $ item , int $ length ) => str_pad ((string ) $ item , $ length , ' ' , STR_PAD_LEFT );
169
169
170
- if ($ seconds < 1 ) {
171
- return $ padder (floor ($ seconds * 1000 ), 3 ) . 'ms ' ;
172
- }
173
-
174
- if ($ seconds < 60 ) {
175
- return $ padder (floor ($ seconds ), 2 ) . 's ' ;
176
- }
170
+ $ daysLeft = floor ($ seconds / 86400 );
171
+ $ hoursLeft = floor (($ seconds - ($ daysLeft * 86400 )) / 3600 );
172
+ $ minutesLeft = floor (($ seconds - ($ daysLeft * 86400 ) - ($ hoursLeft * 3600 )) / 60 );
173
+ $ secondsLeft = floor ($ seconds - ($ daysLeft * 86400 ) - ($ hoursLeft * 3600 ) - ($ minutesLeft * 60 ));
177
174
178
- if ($ seconds < 3600 ) {
179
- $ minutesLeft = floor ($ seconds / 60 );
180
- $ secondsLeft = floor ($ seconds - ($ minutesLeft * 60 ));
175
+ $ output = '' ;
181
176
182
- return $ padder ( $ minutesLeft , 2 ) . ' min '
183
- . ' , ' . $ padder ($ secondsLeft , 2 ) . 's ' ;
177
+ if ( $ daysLeft ) {
178
+ $ output .= $ padder ($ daysLeft , 2 ) . 'd, ' ;
184
179
}
185
180
186
- if ($ seconds < 86400 ) {
187
- $ hoursLeft = floor ($ seconds / 3600 );
188
- $ minutesLeft = floor (($ seconds - ($ hoursLeft * 3600 )) / 60 );
189
- $ secondsLeft = floor ($ seconds - ($ hoursLeft * 3600 ) - ($ minutesLeft * 60 ));
190
-
191
- return $ padder ($ hoursLeft , 2 ) . 'h '
192
- . ', ' . $ padder ($ minutesLeft , 2 ) . 'min '
193
- . ', ' . $ padder ($ secondsLeft , 2 ) . 's ' ;
181
+ if ($ hoursLeft ) {
182
+ $ output .= $ padder ($ hoursLeft , 2 ) . 'h, ' ;
194
183
}
195
184
196
- $ daysLeft = floor ($ seconds / 86400 );
197
- $ hoursLeft = floor (($ seconds - ($ daysLeft * 86400 )) / 3600 );
198
- $ minutesLeft = floor (($ seconds - ($ daysLeft * 86400 ) - ($ hoursLeft * 3600 )) / 60 );
199
- $ secondsLeft = floor ($ seconds - ($ daysLeft * 86400 ) - ($ hoursLeft * 3600 ) - ($ minutesLeft * 60 ));
185
+ if ($ minutesLeft ) {
186
+ $ output .= $ padder ($ minutesLeft , 2 ) . 'm, ' ;
187
+ }
200
188
201
- return $ padder ($ daysLeft , 3 ) . 'd '
202
- . ', ' . $ padder ($ hoursLeft , 2 ) . 'h '
203
- . ', ' . $ padder ($ minutesLeft , 2 ) . 'min '
204
- . ', ' . $ padder ($ secondsLeft , 2 ) . 's ' ;
189
+ $ output .= $ padder ($ secondsLeft , 2 ) . 's ' ;
190
+ return $ output ;
205
191
}
0 commit comments