Skip to content
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

Fix format_time pluralization #1990

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/lib/Default/smr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function word_filter(string $string): string {
// choose correct pluralization based on amount
function pluralise(int|float $amount, string $word, bool $includeAmount = true): string {
$result = $word;
if ($amount !== 1) {
if ((float)$amount !== 1.) {
$result .= 's';
}
if ($includeAmount) {
Expand Down
23 changes: 23 additions & 0 deletions test/SmrTest/lib/functions/FormatTimeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);

namespace SmrTest\lib\functions;

use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;

#[CoversFunction('format_time')]
class FormatTimeTest extends TestCase {

#[TestWith([-60, '1 minute ago', '1m ago'])]
#[TestWith([0, 'now', 'now'])]
#[TestWith([59, 'less than 1 minute', '&lt;1m'])]
#[TestWith([60, '1 minute', '1m'])]
#[TestWith([120, '2 minutes', '2m'])]
#[TestWith([1092131, '1 week, 5 days, 15 hours and 23 minutes', '1w, 5d, 15h and 23m'])]
public function test_format_time(int $seconds, string $expectedLong, string $expectedShort): void {
self::assertSame($expectedLong, format_time($seconds));
self::assertSame($expectedShort, format_time($seconds, short: true));
}

}
1 change: 1 addition & 0 deletions test/SmrTest/lib/functions/PluraliseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PluraliseTest extends TestCase {
#[TestWith([3, true, '3 tests'])]
#[TestWith([1, true, '1 test'])]
#[TestWith([0, true, '0 tests'])]
#[TestWith([1.0, true, '1 test'])]
#[TestWith([0.5, true, '0.5 tests'])]
#[TestWith([3, false, 'tests'])]
#[TestWith([1, false, 'test'])]
Expand Down
Loading