From 249e0c06e4bfc4ed4d0ffc3c768dfe4b60f9efa5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 23 Jul 2018 23:34:40 +0200 Subject: [PATCH] ReverseChronologicalPager: Fix timezone confusion (This change is best tested with Special:Log before changes from 38756eae4, since it seems the $mDay/$mMonth/$mYear values are not directly used anywhere in core after that.) The setTimezone() call did not actually change the offset used for database lookup, because getTimestamp() returns a Unix timestamp, which by definition does not include timezone information. It did change the offset used for year/month/day fields in the interface, but it changed it in the wrong direction: instead of assuming the date is in local timezone and converting to UTC, it assumed the date is in UTC and converted it to local timezone. We don't actually want to do anything with timezones here. For better or worse, the date selectors for pagers have always used UTC dates. The timezone code was only introduced relatively recently in 53fa809a. What we really want for the interface is to display the previous date, relative to the database offset. The interface asks the user to select the month/date up to which to display things (such as "May 2018 (and earlier)"), but the database queries use strict comparison (such as `log_timestamp < '20180601000000'`), so the database offset is calculated to the next date after selected one. The incorrect timezone calculation accidentally did so, but only if the wiki timezone had a negative offset relative to the UTC. If the wiki was using UTC or a timezone with positive offset, the correction was not applied, causing the selected date in the interface to move one day forward from the date that was set. Bug: T171110 Change-Id: I8c2cd398d7c7ac68a8f46ee94cb9e7c6beed5694 --- includes/pager/ReverseChronologicalPager.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/includes/pager/ReverseChronologicalPager.php b/includes/pager/ReverseChronologicalPager.php index 9eef728a93..51824d2f35 100644 --- a/includes/pager/ReverseChronologicalPager.php +++ b/includes/pager/ReverseChronologicalPager.php @@ -81,14 +81,16 @@ abstract class ReverseChronologicalPager extends IndexPager { return null; } - // Treat the given time in the wiki timezone and get a UTC timestamp for the database lookup $timestamp = self::getOffsetDate( $year, $month, $day ); - $timestamp->setTimezone( $this->getConfig()->get( 'Localtimezone' ) ); try { - $this->mYear = (int)$timestamp->format( 'Y' ); - $this->mMonth = (int)$timestamp->format( 'm' ); - $this->mDay = (int)$timestamp->format( 'd' ); + // The timestamp used for DB queries is at midnight of the *next* day after the selected date. + $selectedDate = new DateTime( $timestamp->getTimestamp( TS_ISO_8601 ) ); + $selectedDate = $selectedDate->modify( '-1 day' ); + + $this->mYear = (int)$selectedDate->format( 'Y' ); + $this->mMonth = (int)$selectedDate->format( 'm' ); + $this->mDay = (int)$selectedDate->format( 'd' ); $this->mOffset = $this->mDb->timestamp( $timestamp->getTimestamp() ); } catch ( TimestampException $e ) { // Invalid user provided timestamp (T149257) -- 2.20.1