r43614 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43613‎ | r43614 | r43615 >
Date:18:01, 17 November 2008
Author:mkroetzsch
Status:deferred
Tags:
Comment:
update of Type:Date from Fabian Howahl
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Language.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php
@@ -32,7 +32,7 @@
3333 protected $m_jdn = ''; //numerical time representation similiar to Julian Day Number
3434 protected $m_timeoffset; //contains offset (e.g. timezone)
3535 protected $m_timeannotation; //contains am or pm
36 - protected $m_timeisset = true;
 36+ protected $m_timeisset;
3737 protected $m_yearbc; //true if year is BC
3838 protected $m_months = array("January", "February", "March", "April" , "May" , "June" , "Juli" , "August" , "September" , "October" , "November" , "December");
3939 protected $m_monthsshort = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
@@ -51,15 +51,16 @@
5252 $this->m_timeoffset = 0;
5353 $this->m_timepm = false;
5454 $this->m_timeisset = false;
 55+ $this->m_timeannotation = false;
5556
5657 $this->m_wikivalue = $value;
5758 $filteredvalue = $value; //value without time definition and further abbreviations like PM or BC
5859
5960 //browse string for special abbreviations referring to time like am, pm
6061 if(preg_match("/([Aa]|[Pp])[Mm]/u", $filteredvalue, $match)){
61 - $this->m_timeannotation = strtolower($match[0]);
62 - $regexp = "/(\040|T){0,1}".str_replace("+", "\+", $match[0])."(\040){0,1}/u"; //delete pm/am, preceding and following chars
63 - $filteredvalue = preg_replace($regexp,'', $filteredvalue); //value without am/pm
 62+ $this->m_timeannotation = strtolower($match[0]);
 63+ $regexp = "/(\040|T){0,1}".str_replace("+", "\+", $match[0])."(\040){0,1}/u"; //delete pm/am, preceding and following chars
 64+ $filteredvalue = preg_replace($regexp,'', $filteredvalue); //value without am/pm
6465 }
6566
6667 //browse string for special abbreviations referring to year like AD, BC
@@ -78,25 +79,24 @@
7980
8081 //timezone handling
8182 if(preg_match("/([+\-][0-2]?[0-9](:(30|00))?)/u", $time, $match2)){ //get timezone definition
82 - $offset = $this->normalizeTimeValue($match2[0]);
83 - $sign = 1;
84 - if($offset[0] == '-') $sign = -1;
85 - $offset = substr($offset,1);
86 - list ($offhours, $offminutes, $offseconds) = explode(':',$offset,3);
87 - $offset = $sign * (($offhours / 24) + ($offminutes / (60*24)) + ($offseconds / (3600*24)));
88 - $this->m_timeoffset = $this->m_timeoffset + $offset;
89 - $time = str_replace($match2[0],'',$time);
 83+ $offset = $this->normalizeTimeValue($match2[0]);
 84+ $sign = 1;
 85+ if($offset[0] == '-') $sign = -1;
 86+ $offset = substr($offset,1);
 87+ list ($offhours, $offminutes, $offseconds) = explode(':',$offset,3);
 88+ $offset = $sign * (($offhours / 24) + ($offminutes / (60*24)) + ($offseconds / (3600*24)));
 89+ $this->m_timeoffset = $this->m_timeoffset + $offset;
 90+ $time = str_replace($match2[0],'',$time);
9091 }
9192
9293 list($hours,$minutes,$seconds) = explode(':',$this->normalizeTimeValue($time),3);
9394
9495 //am/pm handling
95 - if($this->m_timeannotation != ''){
96 -
97 - if(!strcmp($this->m_timeannotation,'am') && $hours == 12) $hours = 0;
98 - if(!strcmp($this->m_timeannotation,'pm') && $hours <= 11){
99 - $this->m_timeoffset = 0.5;
100 - }
 96+ if($this->m_timeannotation != false){
 97+ if(!strcmp($this->m_timeannotation,'am') && $hours == 12) $hours = 0;
 98+ if(!strcmp($this->m_timeannotation,'pm') && $hours <= 11){
 99+ $this->m_timeoffset = $this->m_timeoffset + 0.5;
 100+ }
101101 }
102102
103103 $this->m_time = $this->normalizeValue($hours).":".$this->normalizeValue($minutes).":".$this->normalizeValue($seconds);
@@ -171,7 +171,7 @@
172172 $this->m_year = -$this->m_year;
173173 }
174174
175 - //handle offset
 175+ //handle offset
176176 if($this->m_timeoffset != 0){
177177 $this->createJDN();
178178 $this->m_jdn = $this->m_jdn + $this->m_timeoffset;
@@ -181,6 +181,7 @@
182182 if ($this->m_caption === false) {
183183 $this->m_caption = $value;
184184 }
 185+
185186 return true;
186187 }
187188
@@ -278,10 +279,11 @@
279280
280281 public function getExportData() {
281282 if ($this->isValid()) {
282 - $lit = new SMWExpLiteral($this->getXSDValue(), $this, 'http://www.w3.org/2001/XMLSchema#dateTime');
283 - return new SMWExpData($lit);
 283+ $xml = $this->m_year.'-'.$this->normalizeValue($this->m_month).'-'.$this->normalizeValue($this->m_day).'T'.$this->m_time;
 284+ $lit = new SMWExpLiteral($xml, $this, 'http://www.w3.org/2001/XMLSchema#dateTime');
 285+ return new SMWExpData($lit);
284286 } else {
285 - return NULL;
 287+ return NULL;
286288 }
287289 }
288290
@@ -292,9 +294,9 @@
293295 protected function makePrintoutValue() {
294296 global $smwgContLang;
295297 if ($this->m_printvalue === false) {
296 - $time = '';
297 - if($this->m_timeisset) $time = $this->m_time;
298 - $this->m_printvalue = $this->m_day." ".$smwgContLang->getMonthLabel($this->m_month)." ".$this->m_year." ".$time; //MediaWiki date function is not applicable any more (no support for BC Dates...)
 298+ if($this->m_timeisset || !(!$this->m_timeisset && $this->m_time=="00:00:00")) $time = $this->m_time;
 299+ if((int)$this->m_day>0) $day = (int)$this->m_day;
 300+ $this->m_printvalue = $day." ".$smwgContLang->getMonthLabel($this->m_month)." ".$this->m_year." ".$time; //MediaWiki date function is not applicable any more (no support for BC Dates...)
299301 }
300302 }
301303
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Language.php
@@ -110,7 +110,7 @@
111111 * Return the name of the month with the given number.
112112 */
113113 function getMonthLabel($number) {
114 - return $this->m_months[(int)$number];
 114+ return $this->m_months[(int)($number-1)];
115115 }
116116
117117 }

Status & tagging log