r95555 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95554‎ | r95555 | r95556 >
Date:13:59, 26 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
@@ -729,7 +729,7 @@
730730 $result .= str_pad( $this->getYear(), 4, "0", STR_PAD_LEFT ) .
731731 '-' . str_pad( $monthnum, 2, "0", STR_PAD_LEFT );
732732 if ( !$mindefault && ( $this->m_dataitem->getPrecision() < SMWDITime::PREC_YMD ) ) {
733 - $maxday = self::getDayNumberForMonth( $monthnum, $this->getYear(), SMWDITime::CM_GREGORIAN );
 733+ $maxday = SMWDITime::getDayNumberForMonth( $monthnum, $this->getYear(), SMWDITime::CM_GREGORIAN );
734734 $result .= '-' . str_pad( $this->getDay( SMWDITime::CM_GREGORIAN, $maxday ), 2, "0", STR_PAD_LEFT );
735735 } else {
736736 $result .= '-' . str_pad( $this->getDay(), 2, "0", STR_PAD_LEFT );
@@ -768,10 +768,15 @@
769769 /**
770770 * Compute a suitable string to display the given date item.
771771 * @note MediaWiki's date functions are not applicable for the range of historic dates we support.
 772+ *
 773+ * @since 1.6
 774+ *
 775+ * @param SMWDITime $dataitem
 776+ *
772777 * @return string
773778 * @todo Internationalize the CE and BCE strings.
774779 */
775 - public function getCaptionFromDataitem( $dataitem ) {
 780+ public function getCaptionFromDataitem( SMWDITime $dataitem ) {
776781 global $smwgContLang;
777782 if ( $dataitem->getYear() > 0 ) {
778783 $cestring = '';
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php
@@ -103,7 +103,7 @@
104104 */
105105 public function __construct( $calendarmodel, $year, $month = false, $day = false,
106106 $hour = false, $minute = false, $second = false ) {
107 - if ( ( $calendarmodel != SMWDITime::CM_GREGORIAN ) && ( $calendarmodel != SMWDITime::CM_JULIAN ) ) {
 107+ if ( ( $calendarmodel != self::CM_GREGORIAN ) && ( $calendarmodel != self::CM_JULIAN ) ) {
108108 throw new SMWDataItemException( "Unsupported calendar model constant \"$calendarmodel\"." );
109109 }
110110 if ( $year == 0 ) {
@@ -122,17 +122,17 @@
123123 ( $this->m_month < 1 ) || ( $this->m_month > 12 ) ) {
124124 throw new SMWDataItemException( "Part of the date is out of bounds." );
125125 }
126 - if ( $this->m_day > SMWDITime::getDayNumberForMonth( $this->m_month, $this->m_year, $this->m_model ) ) {
 126+ if ( $this->m_day > self::getDayNumberForMonth( $this->m_month, $this->m_year, $this->m_model ) ) {
127127 throw new SMWDataItemException( "Month {$this->m_month} in year {$this->m_year} did not have {$this->m_day} days in this calendar model." );
128128 }
129129 if ( $month === false ) {
130 - $this->m_precision = SMWDITime::PREC_Y;
 130+ $this->m_precision = self::PREC_Y;
131131 } elseif ( $day === false ) {
132 - $this->m_precision = SMWDITime::PREC_YM;
 132+ $this->m_precision = self::PREC_YM;
133133 } elseif ( $hour === false ) {
134 - $this->m_precision = SMWDITime::PREC_YMD;
 134+ $this->m_precision = self::PREC_YMD;
135135 } else {
136 - $this->m_precision = SMWDITime::PREC_YMDT;
 136+ $this->m_precision = self::PREC_YMDT;
137137 }
138138 }
139139
@@ -186,7 +186,7 @@
187187 if ( $calendarmodel == $this->m_model ) {
188188 return $this;
189189 } else {
190 - return SMWDITime::newFromJD( $this->getJD(), $calendarmodel, $this->m_precision );
 190+ return self::newFromJD( $this->getJD(), $calendarmodel, $this->m_precision );
191191 }
192192 }
193193
@@ -209,19 +209,19 @@
210210 }
211211
212212 public function getJD() {
213 - return SMWDITime::date2JD( $this->m_year, $this->m_month, $this->m_day, $this->m_model ) +
214 - SMWDITime::time2JDoffset( $this->m_hours, $this->m_minutes, $this->m_seconds );
 213+ return self::date2JD( $this->m_year, $this->m_month, $this->m_day, $this->m_model ) +
 214+ self::time2JDoffset( $this->m_hours, $this->m_minutes, $this->m_seconds );
215215 }
216216
217217 public function getSerialization() {
218218 $result = strval( $this->m_model ) . '/' . strval( $this->m_year );
219 - if ( $this->m_precision >= SMWDITime::PREC_YM ) {
 219+ if ( $this->m_precision >= self::PREC_YM ) {
220220 $result .= '/' . strval( $this->m_month );
221221 }
222 - if ( $this->m_precision >= SMWDITime::PREC_YMD ) {
 222+ if ( $this->m_precision >= self::PREC_YMD ) {
223223 $result .= '/' . strval( $this->m_day );
224224 }
225 - if ( $this->m_precision >= SMWDITime::PREC_YMDT ) {
 225+ if ( $this->m_precision >= self::PREC_YMDT ) {
226226 $result .= '/' . strval( $this->m_hours ) . '/' . strval( $this->m_minutes ) . '/' . strval( $this->m_seconds );
227227 }
228228 return $result;
@@ -264,15 +264,15 @@
265265 * @return SMWDITime object
266266 */
267267 public static function newFromJD( $jdvalue, $calendarmodel, $precision ) {
268 - list( $year, $month, $day ) = SMWDITime::JD2Date( $jdvalue, $calendarmodel );
269 - if ( $precision <= SMWDITime::PREC_YM ) {
 268+ list( $year, $month, $day ) = self::JD2Date( $jdvalue, $calendarmodel );
 269+ if ( $precision <= self::PREC_YM ) {
270270 $day = false;
271 - if ( $precision == SMWDITime::PREC_Y ) {
 271+ if ( $precision == self::PREC_Y ) {
272272 $month = false;
273273 }
274274 }
275 - if ( $precision == SMWDITime::PREC_YMDT ) {
276 - list( $hour, $minute, $second ) = SMWDITime::JD2Time( $jdvalue );
 275+ if ( $precision == self::PREC_YMDT ) {
 276+ list( $hour, $minute, $second ) = self::JD2Time( $jdvalue );
277277 } else {
278278 $hour = $minute = $second = false;
279279 }
@@ -291,7 +291,7 @@
292292 */
293293 static public function date2JD( $year, $month, $day, $calendarmodel ) {
294294 $astroyear = ( $year < 1 ) ? ( $year + 1 ) : $year;
295 - if ( $calendarmodel == SMWDITime::CM_GREGORIAN ) {
 295+ if ( $calendarmodel == self::CM_GREGORIAN ) {
296296 $a = intval( ( 14 - $month ) / 12 );
297297 $y = $astroyear + 4800 - $a;
298298 $m = $month + 12 * $a - 3;
@@ -326,7 +326,7 @@
327327 * @return array( yearnumber, monthnumber, daynumber )
328328 */
329329 static public function JD2Date( $jdvalue, $calendarmodel ) {
330 - if ( $calendarmodel == SMWDITime::CM_GREGORIAN ) {
 330+ if ( $calendarmodel == self::CM_GREGORIAN ) {
331331 $jdvalue += 2921940; // add the days of 8000 years (this algorithm only works for positive JD)
332332 $j = floor( $jdvalue + 0.5 ) + 32044;
333333 $g = floor( $j / 146097 );
@@ -384,7 +384,7 @@
385385 */
386386 static public function isLeapYear( $year, $calendarmodel ) {
387387 $astroyear = ( $year < 1 ) ? ( $year + 1 ) : $year;
388 - if ( $calendarmodel == SMWDITime::CM_JULIAN ) {
 388+ if ( $calendarmodel == self::CM_JULIAN ) {
389389 return ( $astroyear % 4 ) == 0;
390390 } else {
391391 return ( ( $astroyear % 400 ) == 0 ) ||
@@ -403,8 +403,8 @@
404404 */
405405 static public function getDayNumberForMonth( $month, $year, $calendarmodel ) {
406406 if ( $month !== 2 ) {
407 - return SMWDITime::$m_daysofmonths[$month];
408 - } elseif ( SMWDITime::isLeapYear( $year, $calendarmodel ) ) {
 407+ return self::$m_daysofmonths[$month];
 408+ } elseif ( self::isLeapYear( $year, $calendarmodel ) ) {
409409 return 29;
410410 } else {
411411 return 28;