Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php |
— | — | @@ -80,6 +80,21 @@ |
81 | 81 | protected $m_monthsshort = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); |
82 | 82 | 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')); |
83 | 83 | 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); |
84 | 99 | |
85 | 100 | protected function parseUserValue($value) { |
86 | 101 | global $smwgContLang; |
— | — | @@ -128,7 +143,17 @@ |
129 | 144 | $filteredvalue = trim(preg_replace($regexp,' ', $filteredvalue)); //value without ad/bc |
130 | 145 | } |
131 | 146 | |
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 |
133 | 158 | if(preg_match("/[0-2]?[0-9]:[0-5][0-9](:[0-5][0-9])?([+\-][0-2]?[0-9](:(30|00))?)?/u", $filteredvalue, $match)){ |
134 | 159 | $time = $match[0]; |
135 | 160 | |
— | — | @@ -150,7 +175,7 @@ |
151 | 176 | if($this->m_timeannotation != false){ |
152 | 177 | if(!strcmp($this->m_timeannotation,'am') && $hours == 12) $hours = 0; |
153 | 178 | 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; |
155 | 180 | } |
156 | 181 | } |
157 | 182 | |
— | — | @@ -159,6 +184,22 @@ |
160 | 185 | $filteredvalue = preg_replace($regexp,'', $filteredvalue); //value without time |
161 | 186 | } |
162 | 187 | |
| 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 | + |
163 | 204 | //split array in order to separate the date digits |
164 | 205 | $array = preg_split("/[\040|.|,|\-|\/]+/u", $filteredvalue, 3); //TODO: support   and - again; |
165 | 206 | |
— | — | @@ -227,7 +268,7 @@ |
228 | 269 | //handle offset |
229 | 270 | if ($this->m_timeoffset != 0) { |
230 | 271 | $this->createJD(); |
231 | | - $this->m_jd = $this->m_jd + $this->m_timeoffset; |
| 272 | + $this->m_jd = $this->m_jd - $this->m_timeoffset; |
232 | 273 | $this->JD2Date(); |
233 | 274 | } |
234 | 275 | |