Jelajahi Sumber

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 tahun lalu
induk
melakukan
6580a7e071
1 mengubah file dengan 4 tambahan dan 3 penghapusan
  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
     // Return Unix time as date, relative to today
     public function getDateRelative($timestamp, $format, $daysLimit, $language = "") {
     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));
         $tokens = preg_split("/\s*,\s*/", $this->getText($key, $language));
         if (count($tokens)>=8) {
         if (count($tokens)>=8) {
             if ($days<=$daysLimit || $daysLimit==0) {
             if ($days<=$daysLimit || $daysLimit==0) {