r103991 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103990‎ | r103991 | r103992 >
Date:00:30, 23 November 2011
Author:kaldari
Status:resolved
Tags:
Comment:
better support for timezones
Modified paths:
  • /trunk/extensions/ContributionReporting/DailyTotal_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionReporting/DailyTotal_body.php
@@ -22,17 +22,83 @@
2323
2424 $js = $wgRequest->getBool( 'js', false );
2525
26 - $timezone = $wgRequest->getVal( 'timezone', '0' );
27 - // Make sure it's a number and reasonable
28 - if ( is_nan( $timezone ) || abs( $timezone ) > 100 ) {
29 - $timezone = 0;
30 - }
 26+ $timezone = $wgRequest->getText( 'timezone', '0:00' );
3127
3228 /* Setup */
3329 $wgOut->disable();
3430 $this->sendHeaders();
3531
36 - $start = date( 'Y-m-d' ); // Get the current date
 32+ $zoneList = array (
 33+ '-12:00' => 'Kwajalein',
 34+ '-11:00' => 'Pacific/Midway',
 35+ '-10:00' => 'Pacific/Honolulu',
 36+ '-9:00' => 'America/Anchorage',
 37+ '-09:00' => 'America/Anchorage',
 38+ '-8:00' => 'America/Los_Angeles',
 39+ '-08:00' => 'America/Los_Angeles',
 40+ '-7:00' => 'America/Denver',
 41+ '-07:00' => 'America/Denver',
 42+ '-6:00' => 'America/Tegucigalpa',
 43+ '-06:00' => 'America/Tegucigalpa',
 44+ '-5:00' => 'America/New_York',
 45+ '-05:00' => 'America/New_York',
 46+ '-4:30' => 'America/Caracas',
 47+ '-04:30' => 'America/Caracas',
 48+ '-4:00' => 'America/Halifax',
 49+ '-04:00' => 'America/Halifax',
 50+ '-3:30' => 'America/St_Johns',
 51+ '-03:30' => 'America/St_Johns',
 52+ '-3:00' => 'America/Sao_Paulo',
 53+ '-03:00' => 'America/Sao_Paulo',
 54+ '-2:00' => 'Atlantic/South_Georgia',
 55+ '-02:00' => 'Atlantic/South_Georgia',
 56+ '-1:00' => 'Atlantic/Azores',
 57+ '-01:00' => 'Atlantic/Azores',
 58+ '0:00' => 'UTC',
 59+ '00:00' => 'UTC',
 60+ '1:00' => 'Europe/Belgrade',
 61+ '01:00' => 'Europe/Belgrade',
 62+ '2:00' => 'Europe/Minsk',
 63+ '02:00' => 'Europe/Minsk',
 64+ '3:00' => 'Asia/Kuwait',
 65+ '03:00' => 'Asia/Kuwait',
 66+ '3:30' => 'Asia/Tehran',
 67+ '03:30' => 'Asia/Tehran',
 68+ '4:00' => 'Asia/Muscat',
 69+ '04:00' => 'Asia/Muscat',
 70+ '5:00' => 'Asia/Yekaterinburg',
 71+ '05:00' => 'Asia/Yekaterinburg',
 72+ '5:30' => 'Asia/Kolkata',
 73+ '05:30' => 'Asia/Kolkata',
 74+ '5:45' => 'Asia/Katmandu',
 75+ '05:45' => 'Asia/Katmandu',
 76+ '6:00' => 'Asia/Dhaka',
 77+ '06:00' => 'Asia/Dhaka',
 78+ '6:30' => 'Asia/Rangoon',
 79+ '06:30' => 'Asia/Rangoon',
 80+ '7:00' => 'Asia/Krasnoyarsk',
 81+ '07:00' => 'Asia/Krasnoyarsk',
 82+ '8:00' => 'Asia/Brunei',
 83+ '08:00' => 'Asia/Brunei',
 84+ '9:00' => 'Asia/Seoul',
 85+ '09:00' => 'Asia/Seoul',
 86+ '9:30' => 'Australia/Darwin',
 87+ '09:30' => 'Australia/Darwin',
 88+ '10:00' => 'Australia/Canberra',
 89+ '11:00' => 'Asia/Magadan',
 90+ '12:00' => 'Pacific/Fiji',
 91+ '13:00' => 'Pacific/Tongatapu',
 92+ );
 93+
 94+ // Translate offset to timezone name for PHP
 95+ if ( array_key_exists( $timezone, $zoneList ) ) {
 96+ $timeZoneName = $zoneList[$timezone];
 97+ } else {
 98+ $timeZoneName = 'UTC';
 99+ }
 100+
 101+ $setTimeZone = date_default_timezone_set( $timeZoneName );
 102+ $start = date( 'Y-m-d' ); // Get the current date in the requested timezone
37103 $total = $this->query( $timezone, $start );
38104
39105 $content = "wgFundraisingDailyTotal = $total;";
@@ -54,19 +120,18 @@
55121 if ( $cache != false && $cache != -1 ) {
56122 return $cache;
57123 }
58 - $timeShift = $timezone * 60 * 60;
 124+
59125 // Use database
60126 $dbr = efContributionReportingConnection();
61127 #$dbr = wfGetDB( DB_MASTER );
62128 $conditions = array(
63 - 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) + $timeShift ) ),
64 - 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) + 24 * 60 * 60 + $timeShift ) ),
65129 'converted_amount >= ' . $egFundraiserStatisticsMinimum,
66 - 'converted_amount <= ' . $egFundraiserStatisticsMaximum
 130+ 'converted_amount <= ' . $egFundraiserStatisticsMaximum,
 131+ "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$timezone'),'%Y-%m-%d') = '$start'"
67132 );
 133+
68134 $select = $dbr->select( 'public_reporting',
69135 array(
70 - "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')",
71136 'sum(converted_amount)'
72137 ),
73138 $conditions,

Follow-up revisions

RevisionCommit summaryAuthorDate
r103998MFT r103884, r103947, r103959, r103967, r103991, r103996awjrichards01:24, 23 November 2011
r104000MFT r103884, r103947, r103959, r103967, r103991, r103996awjrichards01:51, 23 November 2011

Status & tagging log