]> git.mxchange.org Git - friendica.git/commitdiff
Switch rounding to flooring in Temporal::getRelativeDate
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 28 Dec 2022 05:32:26 +0000 (00:32 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 28 Dec 2022 05:32:26 +0000 (00:32 -0500)
- Add tests for regression

src/Util/Temporal.php
tests/src/Util/TemporalTest.php

index c3f744ba630796e156311f3a70db096e091842b0..6a0cd659974c0c4df7d3df461c4a5b6370f79eed 100644 (file)
@@ -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');
index fe0429af810d500097dd86d445447c1d4fa1d0e3..4181a51fa30ca3d0f48c57901867668caf98a238 100644 (file)
@@ -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'))
+               );
        }
 }