-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve 'duration' filter #205
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I'm not sure about this. I wanted to keep the same logic as symfony/console, which is a very approximate duration. I admit at lower durations, the approximation can be way off though.
src/DateTimeFormatter.php
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
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.
src/DateTimeFormatter.php
Outdated
@@ -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)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
['%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.
There was a problem hiding this comment.
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.
No description provided.