r90932 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90931‎ | r90932 | r90933 >
Date:02:59, 28 June 2011
Author:yaron
Status:deferred
Tags:
Comment:
Fixed for SMW 1.6
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_SetRecurringEvent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_SetRecurringEvent.php
@@ -50,9 +50,20 @@
5151 SMWOutputs::commitToParser( $parser );
5252 }
5353 }
 54+
 55+ /**
 56+ * Helper function - creates an object of type SMWTimeValue based
 57+ * on a "Julian day" integer
 58+ */
 59+ static protected function jdToTimeValue( $jd ) {
 60+ $timeDataItem = SMWDITime::newFromJD( $jd, SMWDITime::CM_GREGORIAN, SMWDITime::PREC_YMDT );
 61+ $timeValue = new SMWTimeValue( '_dat' );
 62+ $timeValue->setDataItem( $timeDataItem );
 63+ return $timeValue;
 64+ }
5465
5566 /**
56 - * Helper function used by doSetRecurringEvent(), as well as the
 67+ * Helper function used in this class, as well as by the
5768 * Semantic Internal Objects extension
5869 *
5970 * @param Parser &$parser The current parser
@@ -104,7 +115,7 @@
105116
106117 foreach ( $excluded_dates as $date_str ) {
107118 $date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str );
108 - $excluded_dates_jd[] = $date->getDataItem()->getSerialization();
 119+ $excluded_dates_jd[] = $date->getDataItem()->getJD();
109120 }
110121 break;
111122 default:
@@ -137,11 +148,11 @@
138149
139150 // Get the Julian day value for both the start and end date.
140151 if ( !is_null( $end_date ) ) {
141 - $end_date_jd = $end_date->getDataItem()->getSerialization();
 152+ $end_date_jd = $end_date->getDataItem()->getJD();
142153 }
143154
144155 $cur_date = $start_date;
145 - $cur_date_jd = $start_date->getDataItem()->getSerialization();
 156+ $cur_date_jd = $start_date->getDataItem()->getJD();
146157 $i = 0;
147158 $reached_end_date = false;
148159
@@ -190,7 +201,7 @@
191202 // keep incrementing by a week, until we get there.
192203 do {
193204 $cur_date_jd += 7;
194 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
 205+ $cur_date = self::jdToTimeValue( $cur_date_jd );
195206 $right_month = ( $cur_date->getMonth() == $new_month );
196207
197208 if ( $week_num < 0 ) {
@@ -198,19 +209,19 @@
199210
200211 do {
201212 $next_week_jd += 7;
202 - $next_week_date = SMWDataValueFactory::newTypeIDValue( '_dat', $next_week_jd );
 213+ $next_week_date = self::jdToTimeValue( $next_week_jd );
203214 $right_week = ( $next_week_date->getMonth() != $new_month ) || ( $next_week_date->getYear() != $new_year );
204215 } while ( !$right_week );
205216
206217 $cur_date_jd = $next_week_jd + ( 7 * $week_num );
207 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
 218+ $cur_date = self::jdToTimeValue( $cur_date_jd );
208219 } else {
209220 $cur_week_num = ceil( $cur_date->getDay() / 7 );
210221 $right_week = ( $cur_week_num == $week_num );
211222
212223 if ( $week_num == 5 && ( $cur_date->getMonth() % 12 == ( $new_month + 1 ) % 12 ) ) {
213224 $cur_date_jd -= 7;
214 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
 225+ $cur_date = self::jdToTimeValue( $cur_date_jd );
215226 $right_month = $right_week = true;
216227 }
217228 }
@@ -218,7 +229,7 @@
219230 } else { // $unit == 'day' or 'week'
220231 // Assume 'day' if it's none of the above.
221232 $cur_date_jd += ( $unit === 'week' ) ? 7 * $period : $period;
222 - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd );
 233+ $cur_date = self::jdToTimeValue( $cur_date_jd );
223234 }
224235
225236 // should we stop?
@@ -237,4 +248,4 @@
238249 return array( $property_name, $all_date_strings, $unused_params );
239250 }
240251
241 -}
\ No newline at end of file
 252+}