jenkins-bot has submitted this change and it was merged.

Change subject: Date header should be converted to user local time for 
comparison
......................................................................


Date header should be converted to user local time for comparison

bug: 53285
Change-Id: I62a87f9c5f03bf3473357d64f1266d93065262c0
---
M api/ApiEchoNotifications.php
1 file changed, 20 insertions(+), 14 deletions(-)

Approvals:
  Matthias Mullie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/api/ApiEchoNotifications.php b/api/ApiEchoNotifications.php
index 20182b0..25ddb83 100644
--- a/api/ApiEchoNotifications.php
+++ b/api/ApiEchoNotifications.php
@@ -86,22 +86,15 @@
                                $event->setBundleHash( 
$row->notification_bundle_display_hash );
                        }
 
-                       $timestamp = new MWTimestamp( 
$row->notification_timestamp );
-                       // UTC timestamp in UNIX format used for loading more 
notification
-                       $timestampUTCUnix = $timestamp->getTimestamp( TS_UNIX );
-                       // Adjust for the user's timezone
-                       $timestamp->offsetForUser( $user );
-                       $timestampUnix = $timestamp->getTimestamp( TS_UNIX );
-                       $timestampMw = $timestamp->getTimestamp( TS_MW );
+                       $timestampMw = self::getUserLocalTime( $user, 
$row->notification_timestamp );
 
                        // Start creating date section header
-                       $today = wfTimestamp( TS_MW );
-                       $yesterday = wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, 
$today ) - 24 * 3600 );
-
-                       if ( substr( $today, 0, 8 ) === substr( $timestampMw, 
0, 8 ) ) {
+                       $now = wfTimestamp();
+                       $dateFormat = substr( $timestampMw, 0, 8 );
+                       if ( substr( self::getUserLocalTime( $user, $now ), 0, 
8 ) === $dateFormat ) {
                                // 'Today'
                                $date = wfMessage( 'echo-date-today' 
)->escaped();
-                       } elseif ( substr( $yesterday, 0, 8 ) === substr( 
$timestampMw, 0, 8 ) ) {
+                       } elseif ( substr( self::getUserLocalTime( $user, $now 
- 86400 ), 0, 8 ) === $dateFormat ) {
                                // 'Yesterday'
                                $date = wfMessage( 'echo-date-yesterday' 
)->escaped();
                        } else {
@@ -117,8 +110,9 @@
                                'type' => $event->getType(),
                                'category' => $event->getCategory(),
                                'timestamp' => array(
-                                       'utcunix' => $timestampUTCUnix,
-                                       'unix' => $timestampUnix,
+                                       // UTC timestamp in UNIX format used 
for loading more notification
+                                       'utcunix' => wfTimestamp( TS_UNIX, 
$row->notification_timestamp ),
+                                       'unix' => self::getUserLocalTime( 
$user, $row->notification_timestamp, TS_UNIX ),
                                        'mw' => $timestampMw,
                                        'date' => $date
                                ),
@@ -159,6 +153,18 @@
                return $output;
        }
 
+       /**
+        * Internal helper function for converting UTC timezone to a user's 
timezone
+        * @param $user User
+        * @param $ts string
+        * @param $format output format
+        */
+       private static function getUserLocalTime( $user, $ts, $format = TS_MW ) 
{
+               $timestamp = new MWTimestamp( $ts );
+               $timestamp->offsetForUser( $user );
+               return $timestamp->getTimestamp( $format );
+       }
+
        public function getAllowedParams() {
                return array(
                        'prop' => array(

-- 
To view, visit https://gerrit.wikimedia.org/r/80688
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I62a87f9c5f03bf3473357d64f1266d93065262c0
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to