r96313 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96312‎ | r96313 | r96314 >
Date:03:48, 6 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added new function, getJD(), as another fix for SMW 1.6: correctly handles the case of invalid date values
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_SetRecurringEvent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_SetRecurringEvent.php
@@ -61,6 +61,22 @@
6262 $timeValue->setDataItem( $timeDataItem );
6363 return $timeValue;
6464 }
 65+
 66+ /**
 67+ * Returns the "Julian day" value from an object of type
 68+ * SMWTimeValue.
 69+ */
 70+ static public function getJD( $dateDataValue ) {
 71+ if ( is_null( $dateDataValue ) ) {
 72+ return null;
 73+ }
 74+ $dateDataItem = $dateDataValue->getDataItem();
 75+ // This might have returned an 'SMWDIError' object.
 76+ if ( $dateDataItem instanceof SMWDITime ) {
 77+ return $dateDataItem->getJD();
 78+ }
 79+ return null;
 80+ }
6581
6682 /**
6783 * Helper function used in this class, as well as by the
@@ -115,7 +131,7 @@
116132
117133 foreach ( $excluded_dates as $date_str ) {
118134 $date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str );
119 - $excluded_dates_jd[] = $date->getDataItem()->getJD();
 135+ $excluded_dates_jd[] = self::getJD( $date );
120136 }
121137 break;
122138 default:
@@ -147,12 +163,10 @@
148164 }
149165
150166 // Get the Julian day value for both the start and end date.
151 - if ( !is_null( $end_date ) ) {
152 - $end_date_jd = $end_date->getDataItem()->getJD();
153 - }
 167+ $end_date_jd = self::getJD( $end_date );
154168
155169 $cur_date = $start_date;
156 - $cur_date_jd = $start_date->getDataItem()->getJD();
 170+ $cur_date_jd = self::getJD( $cur_date );
157171 $i = 0;
158172 $reached_end_date = false;
159173