Skip to content

Commit d7ec6b2

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: minor Fix build Remove variable [Console] Helpers updated to optimize the time formating
2 parents 8fd3f89 + 148ab69 commit d7ec6b2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

components/console/helpers/formatterhelper.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,20 @@ If you don't want to use suffix at all, pass an empty string::
119119
$truncatedMessage = $formatter->truncate('test', 10);
120120
// result: test
121121
// because length of the "test..." string is shorter than 10
122+
123+
Formatting Time
124+
~~~~~~~~~~~~~~~
125+
126+
Sometimes you want to format seconds to time. This is possible with the
127+
:method:`Symfony\\Component\\Console\\Helper\\FormatterHelper::formatTime` method.
128+
The first argument is the seconds to format and the second argument is the
129+
precision (default ``1``) of the result::
130+
131+
$formatter->truncate(42); // 42 secs
132+
$formatter->truncate(125); // 2 mins
133+
$formatter->truncate(125, 2); // 2 mins, 5 secs
134+
$formatter->truncate(172799, 4); // 1 day, 23 hrs, 59 mins, 59 secs
135+
136+
.. versionadded:: 6.4
137+
138+
The support for exact times were introduced in Symfony 6.4.

components/console/helpers/progressbar.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,14 @@ current progress of the bar. Here is a list of the built-in placeholders:
243243
* ``memory``: The current memory usage;
244244
* ``message``: used to display arbitrary messages in the progress bar (as explained later).
245245

246+
The time fields ``elapsed``, ``remaining`` and ``estimated`` are displayed with
247+
a precision of 2. That means ``172799`` seconds are displayed as
248+
``1 day, 23 hrs`` instead of ``1 day, 23 hrs, 59 mins, 59 secs``.
249+
246250
For instance, here is how you could set the format to be the same as the
247251
``debug`` one::
248252

249-
$progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
253+
$progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:16s%/%estimated:-16s% %memory:6s%');
250254

251255
Notice the ``:6s`` part added to some placeholders? That's how you can tweak
252256
the appearance of the bar (formatting and alignment). The part after the colon

0 commit comments

Comments
 (0)