mirror of
https://github.com/friendica/friendica
synced 2025-05-01 09:04:24 +02:00
Add ClockInterface dependency to Temporal::getRelativeDate
- Remove unused $format parameter
This commit is contained in:
parent
60551e6277
commit
53c0fffbec
3 changed files with 27 additions and 22 deletions
|
@ -22,6 +22,8 @@
|
|||
namespace Friendica\Test\src\Util;
|
||||
|
||||
use Friendica\DI;
|
||||
use Friendica\Util\Clock\FrozenClock;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Temporal;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
@ -35,26 +37,27 @@ class TemporalTest extends TestCase
|
|||
*/
|
||||
public function testGetRelativeDate()
|
||||
{
|
||||
// "never" would should be returned
|
||||
$clock = new FrozenClock();
|
||||
|
||||
// "never" should be returned
|
||||
self::assertEquals(
|
||||
Temporal::getRelativeDate(''),
|
||||
Temporal::getRelativeDate('', true, $clock),
|
||||
DI::l10n()->t('never')
|
||||
);
|
||||
|
||||
// Format current date/time into "MySQL" format
|
||||
$now = date('Y-m-d H:i:s');
|
||||
self::assertEquals(
|
||||
Temporal::getRelativeDate($now),
|
||||
Temporal::getRelativeDate($clock->now()->format(DateTimeFormat::MYSQL), true, $clock),
|
||||
DI::l10n()->t('less than a second ago')
|
||||
);
|
||||
|
||||
// Format current date/time - 1 minute into "MySQL" format
|
||||
$minuteAgo = date('Y-m-d H:i:s', time() - 60);
|
||||
$minuteAgo = date('Y-m-d H:i:s', $clock->now()->getTimestamp() - 60);
|
||||
$format = DI::l10n()->t('%1$d %2$s ago');
|
||||
|
||||
// Should be both equal
|
||||
self::assertEquals(
|
||||
Temporal::getRelativeDate($minuteAgo),
|
||||
Temporal::getRelativeDate($minuteAgo, true, $clock),
|
||||
sprintf($format, 1, DI::l10n()->t('minute'))
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue