99namespace Inhere \Console \Util ;
1010
1111use Toolkit \Cli \ColorTag ;
12+ use Toolkit \Stdlib \Helper \Format ;
1213use Toolkit \Stdlib \Helper \JsonHelper ;
1314use Toolkit \Stdlib \Str ;
1415use Toolkit \Sys \Sys ;
1516use function array_keys ;
1617use function array_merge ;
17- use function count ;
18- use function date ;
1918use function explode ;
20- use function floor ;
2119use function implode ;
2220use function is_array ;
2321use function is_bool ;
2422use function is_int ;
2523use function is_numeric ;
2624use function is_scalar ;
2725use function rtrim ;
28- use function sprintf ;
2926use function str_repeat ;
3027use function str_replace ;
3128use function strpos ;
@@ -169,28 +166,18 @@ public static function alignOptions(array $options): array
169166 }
170167
171168 /**
172- * @param float $memory
173- *
174- * @return string
175169 * ```
176170 * FormatUtil::memoryUsage(memory_get_usage(true));
177171 * ```
172+ *
173+ * @param float|int $memory
174+ *
175+ * @return string
176+ * @deprecated use Format::memory($secs);
178177 */
179178 public static function memoryUsage ($ memory ): string
180179 {
181- if ($ memory >= 1024 * 1024 * 1024 ) {
182- return sprintf ('%.2f Gb ' , $ memory / 1024 / 1024 / 1024 );
183- }
184-
185- if ($ memory >= 1024 * 1024 ) {
186- return sprintf ('%.2f Mb ' , $ memory / 1024 / 1024 );
187- }
188-
189- if ($ memory >= 1024 ) {
190- return sprintf ('%.2f Kb ' , $ memory / 1024 );
191- }
192-
193- return sprintf ('%d B ' , $ memory );
180+ return Format::memory ($ memory );
194181 }
195182
196183 /**
@@ -199,36 +186,11 @@ public static function memoryUsage($memory): string
199186 * @param int $secs
200187 *
201188 * @return string
189+ * @deprecated use Format::howLongAgo($secs);
202190 */
203191 public static function howLongAgo (int $ secs ): string
204192 {
205- static $ timeFormats = [
206- [0 , '< 1 sec ' ],
207- [1 , '1 sec ' ],
208- [2 , 'secs ' , 1 ],
209- [60 , '1 min ' ],
210- [120 , 'mins ' , 60 ],
211- [3600 , '1 hr ' ],
212- [7200 , 'hrs ' , 3600 ],
213- [86400 , '1 day ' ],
214- [172800 , 'days ' , 86400 ],
215- ];
216-
217- foreach ($ timeFormats as $ index => $ format ) {
218- if ($ secs >= $ format [0 ]) {
219- $ next = $ timeFormats [$ index + 1 ] ?? false ;
220-
221- if (($ next && $ secs < $ next [0 ]) || $ index === count ($ timeFormats ) - 1 ) {
222- if (2 === count ($ format )) {
223- return $ format [1 ];
224- }
225-
226- return floor ($ secs / $ format [2 ]) . ' ' . $ format [1 ];
227- }
228- }
229- }
230-
231- return date ('Y-m-d H:i:s ' , $ secs );
193+ return Format::howLongAgo ($ secs );
232194 }
233195
234196 /**
0 commit comments