r54736 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54735‎ | r54736 | r54737 >
Date:20:35, 10 August 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
included patch by Temlakos: much improved timezone support
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php
@@ -80,6 +80,21 @@
8181 protected $m_monthsshort = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
8282 protected $m_formats = array( SMW_Y => array('year'), SMW_YM => array('year','month'), SMW_MY => array('month','year'), SMW_YDM => array('year','day','month'), SMW_YMD => array('year','month','day'), SMW_DMY => array('day','month','year'), SMW_MDY => array('month','day','year'));
8383 protected $m_daysofmonths = array ( 1 => 31, 2 => 29, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31 );
 84+ // Time zone monikers and their associated offsets in hours and fractions of hours
 85+ protected $m_tz = array("A" => 1, "ACDT" => 10.5, "ACST" => 9.5, "ADT" => -3, "AEDT" => 11,
 86+ "AEST" => 10, "AKDT" => -8, "AKST" => -9, "AST" => -4, "AWDT" => 9, "AWST" => 8,
 87+ "B" => 2, "BST" => 1, "C" => 3, "CDT" => -5, "CEDT" => 2, "CEST" => 2,
 88+ "CET" => 1, "CST" => -6, "CXT" => 7, "D" => 4, "E" => 5, "EDT" => -4,
 89+ "EEDT" => 3, "EEST" => 3, "EET" => 2, "EST" => -5, "F" => 6, "G" => 7,
 90+ "GMT" => 0, "H" => 8, "HAA" => -3, "HAC" => -5, "HADT" => -9, "HAE" => -4,
 91+ "HAP" => -7, "HAR" => -6, "HAST" => -10, "HAT" => -2.5, "HAY" => -8,
 92+ "HNA" => -4, "HNC" => -6, "HNE" => -5, "HNP" => -8, "HNR" => -7, "HNT" => -3.5,
 93+ "HNY" => -9, "I" => 9, "IST" => 1, "K" => 10, "L" => 11, "M" => 12,
 94+ "MDT" => -6, "MESZ" => 2, "MEZ" => 1, "MSD" => 4, "MSK" => 3, "MST" => -7,
 95+ "N" => -1, "NDT" => -2.5, "NFT" => 11.5, "NST" => -3.5, "O" => -2, "P" => -3,
 96+ "PDT" => -7, "PST" => -8, "Q" => -4, "R" => -5, "S" => -6, "T" => -7,
 97+ "U" => -8, "UTC" => 0, "V" => -9, "W" => -10, "WDT" => 9, "WEDT" => 1,
 98+ "WEST" => 1, "WET" => 0, "WST" => 8, "X" => -11, "Y" => -12, "Z" => 0);
8499
85100 protected function parseUserValue($value) {
86101 global $smwgContLang;
@@ -128,7 +143,17 @@
129144 $filteredvalue = trim(preg_replace($regexp,' ', $filteredvalue)); //value without ad/bc
130145 }
131146
132 - //browse string for time value
 147+ //browse string in advance for timezone monikers ("EST", "WET", "MESZ", etc.)
 148+ $regexptz = "/A[CEKW]?[DS]T|BST|CXT|[CEW]([DES]|E[DS])T|" .
 149+ "GMT|H(A[DS]T|[AN][ACEPRTY])|IST|M(DT|E(S)?Z|S[DKT])|N[DFS]T|P[DS]T|UTC/u";
 150+ if(preg_match($regexptz, $filteredvalue, $match)) {
 151+ // Retrieve the offset and store it as the initial time offset value.
 152+ $this->m_timeoffset = $this->m_timeoffset + $this->m_tz[$match[0]]/24;
 153+ $regexp = "/(\040|T){0,1}".str_replace("+", "\+", $match[0])."(\040){0,1}/u"; //delete tz moniker and preceding and following chars
 154+ $filteredvalue = preg_replace($regexp,'', $filteredvalue); //value without the tz moniker
 155+ }
 156+
 157+ //browse string for civilian time value
133158 if(preg_match("/[0-2]?[0-9]:[0-5][0-9](:[0-5][0-9])?([+\-][0-2]?[0-9](:(30|00))?)?/u", $filteredvalue, $match)){
134159 $time = $match[0];
135160
@@ -150,7 +175,7 @@
151176 if($this->m_timeannotation != false){
152177 if(!strcmp($this->m_timeannotation,'am') && $hours == 12) $hours = 0;
153178 if(!strcmp($this->m_timeannotation,'pm') && $hours <= 11){
154 - $this->m_timeoffset = $this->m_timeoffset + 0.5;
 179+ $this->m_timeoffset = $this->m_timeoffset - 0.5;
155180 }
156181 }
157182
@@ -159,6 +184,22 @@
160185 $filteredvalue = preg_replace($regexp,'', $filteredvalue); //value without time
161186 }
162187
 188+ //browse string for military time value
 189+ if(preg_match("/([0-1][0-9]|2[0-3])[0-5][0-9]([0-5][0-9])?[A-IK-Z]/u",$filteredvalue, $match)){
 190+ $time = $match[0];
 191+ //timezone handling (Zulu, Romeo, Sierra, etc.)
 192+ if(preg_match("/[A-IK-Z]/u",$time, $match2)){//get military timezone offset
 193+ $this->m_timeoffset = $this->m_timeoffset + $this->m_tz[$match2[0]]/24;
 194+ $time = str_replace($match2[0],'',$time);//strip away the one-letter moniker
 195+ }
 196+ $hours = substr($time,0,2);
 197+ $minutes = substr($time,2,2);
 198+ $seconds = (strlen($time) > 4) ? substr($time,4,2) : '00';
 199+ $this->m_time = $this->normalizeValue($hours).":".$this->normalizeValue($minutes).":".$this->normalizeValue($seconds);
 200+ $regexp = "/(\040|T){0,1}".str_replace("+", "\+", $match[0])."(\040){0,1}/u"; //delete time value and preceding and following chars
 201+ $filteredvalue = preg_replace($regexp,'', $filteredvalue); //value without time
 202+ }
 203+
163204 //split array in order to separate the date digits
164205 $array = preg_split("/[\040|.|,|\-|\/]+/u", $filteredvalue, 3); //TODO: support &nbsp and - again;
165206
@@ -227,7 +268,7 @@
228269 //handle offset
229270 if ($this->m_timeoffset != 0) {
230271 $this->createJD();
231 - $this->m_jd = $this->m_jd + $this->m_timeoffset;
 272+ $this->m_jd = $this->m_jd - $this->m_timeoffset;
232273 $this->JD2Date();
233274 }
234275

Status & tagging log