Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/DateTimeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function formatDiff(
*
* @source https://github.com/symfony/symfony/blob/ad72245261792c6b5d2db821fcbd141b11095215/src/Symfony/Component/Console/Helper/Helper.php#L97
*/
public function formatDuration(float $seconds, string $locale = null): string
public function formatDuration(float $seconds, int $precision = 2, string $locale = null): string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

Suggested change
public function formatDuration(float $seconds, int $precision = 2, string $locale = null): string
public function formatDuration(float $seconds, string $locale = null, ?int $precision = null): string

Adding the $precision before $locale is a BC break. Default to null to keep current behavior by default.

{
static $timeFormats = [
[0, 'duration.none'],
Expand All @@ -78,7 +78,7 @@ public function formatDuration(float $seconds, string $locale = null): string

return $this->translator->trans(
$format[1],
['%count%' => floor($seconds / $format[2])],
['%count%' => number_format($seconds / $format[2], $precision)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
['%count%' => number_format($seconds / $format[2], $precision)],
['%count%' => null === $precision ? floor($seconds / $format[2]) : number_format($seconds / $format[2], $precision)],

To keep the current behaviour.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous logic was wrong :( I remove the precision parameter and add a private method that format the seconds into float number.

'time',
$locale
);
Expand Down