瀏覽代碼

fixed a bug in `getDateRelative()`

I have modified `getDateRelative()` so that the basis for calculating the time difference is the date and not the time (86400s (24h)). This had the consequence that `getDateRelative()` a page that was created yesterday at 18:00 o'clock, today at 13:00 o'clock `today` output, which is definitely wrong. Now the date of the publication is checked and compared with today's date.
Robert Pfotenhauer 1 年之前
父節點
當前提交
6580a7e071
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      system/extensions/core.php

+ 4 - 3
system/extensions/core.php

@@ -876,9 +876,10 @@ class YellowLanguage {
     
     // Return Unix time as date, relative to today
     public function getDateRelative($timestamp, $format, $daysLimit, $language = "") {
-        $timeDifference = time() - $timestamp;
-        $days = abs(intval($timeDifference/86400));
-        $key = $timeDifference>=0 ? "coreDatePast" : "coreDateFuture";
+        $today = strtotime(date('Y-m-d')); // Today's date without time information
+        $dateDifference = $today - strtotime(date('Y-m-d', $timestamp)); // Difference in days between today and the specified date
+        $days = abs(intval($dateDifference/86400));
+        $key = $dateDifference>=0 ? "coreDatePast" : "coreDateFuture";
         $tokens = preg_split("/\s*,\s*/", $this->getText($key, $language));
         if (count($tokens)>=8) {
             if ($days<=$daysLimit || $daysLimit==0) {