mirror of
https://github.com/friendica/friendica
synced 2024-12-22 19:20:17 +00:00
Switch rounding to flooring in Temporal::getRelativeDate
- Add tests for regression
This commit is contained in:
parent
53c0fffbec
commit
a1dc6e2417
2 changed files with 19 additions and 1 deletions
|
@ -361,7 +361,7 @@ class Temporal
|
|||
foreach ($a as $secs => $str) {
|
||||
$d = $etime / $secs;
|
||||
if ($d >= 1) {
|
||||
$r = round($d);
|
||||
$r = floor($d);
|
||||
// translators - e.g. 22 hours ago, 1 minute ago
|
||||
if($isfuture){
|
||||
$format = DI::l10n()->t('in %1$d %2$s');
|
||||
|
|
|
@ -60,5 +60,23 @@ class TemporalTest extends TestCase
|
|||
Temporal::getRelativeDate($minuteAgo, true, $clock),
|
||||
sprintf($format, 1, DI::l10n()->t('minute'))
|
||||
);
|
||||
|
||||
$almostAnHourAgoInterval = new \DateInterval('PT59M59S');
|
||||
$almostAnHourAgoInterval->invert = 1;
|
||||
$almostAnHourAgo = (clone $clock->now())->add($almostAnHourAgoInterval);
|
||||
|
||||
self::assertEquals(
|
||||
Temporal::getRelativeDate($almostAnHourAgo->format(DateTimeFormat::MYSQL), true, $clock),
|
||||
sprintf($format, 59, DI::l10n()->t('minutes'))
|
||||
);
|
||||
|
||||
$anHourAgoInterval = new \DateInterval('PT1H');
|
||||
$anHourAgoInterval->invert = 1;
|
||||
$anHourAgo = (clone $clock->now())->add($anHourAgoInterval);
|
||||
|
||||
self::assertEquals(
|
||||
Temporal::getRelativeDate($anHourAgo->format(DateTimeFormat::MYSQL), true, $clock),
|
||||
sprintf($format, 1, DI::l10n()->t('hour'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue