]> git.wh0rd.org - tt-rss.git/commitdiff
smart_date_time: properly support local TZ; use user-defined date formats
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 7 Nov 2010 21:31:43 +0000 (00:31 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sun, 7 Nov 2010 21:31:43 +0000 (00:31 +0300)
functions.php

index 5c63eae043e8e2c88bad0e850afe7d75de6672fc..baf302de3a272952da68ff26f21217163256763a 100644 (file)
                $user_timestamp = $dt->format('U') + $user_tz->getOffset($dt);
 
                if (!$no_smart_dt && get_pref($link, 'HEADLINES_SMART_DATE', $owner_uid)) {
-                       return smart_date_time($user_timestamp);
+                       return smart_date_time($link, $user_timestamp, 
+                               $user_tz->getOffset($dt), $owner_uid);
                } else {
                        if ($long)
                                $format = get_pref($link, 'LONG_DATE_FORMAT', $owner_uid);
                }
        }
 
-       function smart_date_time($timestamp) {
-               if (date("Y.m.d", $timestamp) == date("Y.m.d")) {
+       function smart_date_time($link, $timestamp, $tz_offset = 0, $owner_uid = false) {
+               if (!$owner_uid) $owner_uid = $_SESSION['uid'];
+
+               if (date("Y.m.d", $timestamp) == date("Y.m.d", time() + $tz_offset)) {
                        return date("G:i", $timestamp);
-               } else if (date("Y", $timestamp) == date("Y")) {
-                       return date("M d, G:i", $timestamp);
+               } else if (date("Y", $timestamp) == date("Y", time() + $tz_offset)) {
+                       $format = get_pref($link, 'SHORT_DATE_FORMAT', $owner_uid);
+                       return date($format, $timestamp);
                } else {
-                       return date("Y/m/d, G:i", $timestamp);
+                       $format = get_pref($link, 'LONG_DATE_FORMAT', $owner_uid);
+                       return date($format, $timestamp);
                }
        }