File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,6 +160,40 @@ function nicesize($size)
160160 }
161161}
162162
163+ if (!function_exists ('niceEta ' )) {
164+ /**
165+ * Format ETA seconds into human-readable format.
166+ *
167+ * Converts seconds into a user-friendly time format:
168+ * - Less than 60 seconds: "45s"
169+ * - Less than 1 hour: "5m 30s"
170+ * - 1 hour or more: "2h 15m"
171+ *
172+ * @param float $seconds Number of seconds to format
173+ * @return string Human-readable time format
174+ *
175+ * @example
176+ * niceEta(45.5); // "46s"
177+ * niceEta(150); // "2m 30s"
178+ * niceEta(3600); // "1h 0m"
179+ * niceEta(8100); // "2h 15m"
180+ */
181+ function niceEta (float $ seconds ): string
182+ {
183+ if ($ seconds < 60 ) {
184+ return sprintf ('%.0fs ' , $ seconds );
185+ } elseif ($ seconds < 3600 ) {
186+ $ minutes = floor ($ seconds / 60 );
187+ $ remainingSeconds = $ seconds % 60 ;
188+ return sprintf ('%.0fm %.0fs ' , $ minutes , $ remainingSeconds );
189+ } else {
190+ $ hours = floor ($ seconds / 3600 );
191+ $ minutes = floor (($ seconds % 3600 ) / 60 );
192+ return sprintf ('%.0fh %.0fm ' , $ hours , $ minutes );
193+ }
194+ }
195+ }
196+
163197if (!function_exists ('data_is_json ' )) {
164198 /**
165199 * @param $string
You can’t perform that action at this time.
0 commit comments