]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Temporal.php
Merge pull request #12390 from annando/fixes
[friendica.git] / src / Util / Temporal.php
index 72271c06f10d99e558c40b7681a7d746d7783efd..f6805a92224b4eaf8eda09789bf04b37edff1352 100644 (file)
@@ -24,7 +24,6 @@ namespace Friendica\Util;
 use DateTime;
 use DateTimeZone;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\DI;
 
@@ -239,7 +238,7 @@ class Temporal
                bool $required = false): string
        {
                // First day of the week (0 = Sunday)
-               $firstDay = DI::pConfig()->get(Session::getLocalUser(), 'system', 'first_day_of_week', 0);
+               $firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'first_day_of_week', 0);
 
                $lang = substr(DI::l10n()->getCurrentLang(), 0, 2);
 
@@ -306,13 +305,14 @@ class Temporal
         * Results relative to current timezone.
         * Limited to range of timestamps.
         *
-        * @param string $posted_date MySQL-formatted date string (YYYY-MM-DD HH:MM:SS)
-        * @param string $format (optional) Parsed with sprintf()
+        * @param string $posted_date  MySQL-formatted date string (YYYY-MM-DD HH:MM:SS)
+        * @param string $format       (optional) Parsed with sprintf()
+        * @param bool   $compare_time Compare date (false) or date and time (true). "true" is default.
         *    <tt>%1$d %2$s ago</tt>, e.g. 22 hours ago, 1 minute ago
         *
         * @return string with relative date
         */
-       public static function getRelativeDate(string $posted_date = null, string $format = null): string
+       public static function getRelativeDate(string $posted_date = null, string $format = null, bool $compare_time = true): string
        {
                if (empty($posted_date) || $posted_date <= DBA::NULL_DATETIME) {
                        return DI::l10n()->t('never');
@@ -325,11 +325,18 @@ class Temporal
                        return DI::l10n()->t('never');
                }
 
+               $now = time();
+       
+               if (!$compare_time) {
+                       $now = mktime(0, 0, 0, date('m', $now), date('d', $now), date('Y', $now));
+                       $abs = mktime(0, 0, 0, date('m', $abs), date('d', $abs), date('Y', $abs));
+               }
+
                $isfuture = false;
-               $etime = time() - $abs;
+               $etime = $now - $abs;
 
                if ($etime < 1 && $etime >= 0) {
-                       return DI::l10n()->t('less than a second ago');
+                       return $compare_time ? DI::l10n()->t('less than a second ago') : DI::l10n()->t('today');
                }
 
                if ($etime < 0){