Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_SetRecurringEvent.php |
— | — | @@ -50,9 +50,20 @@ |
51 | 51 | SMWOutputs::commitToParser( $parser ); |
52 | 52 | } |
53 | 53 | } |
| 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 | + } |
54 | 65 | |
55 | 66 | /** |
56 | | - * Helper function used by doSetRecurringEvent(), as well as the |
| 67 | + * Helper function used in this class, as well as by the |
57 | 68 | * Semantic Internal Objects extension |
58 | 69 | * |
59 | 70 | * @param Parser &$parser The current parser |
— | — | @@ -104,7 +115,7 @@ |
105 | 116 | |
106 | 117 | foreach ( $excluded_dates as $date_str ) { |
107 | 118 | $date = SMWDataValueFactory::newTypeIDValue( '_dat', $date_str ); |
108 | | - $excluded_dates_jd[] = $date->getDataItem()->getSerialization(); |
| 119 | + $excluded_dates_jd[] = $date->getDataItem()->getJD(); |
109 | 120 | } |
110 | 121 | break; |
111 | 122 | default: |
— | — | @@ -137,11 +148,11 @@ |
138 | 149 | |
139 | 150 | // Get the Julian day value for both the start and end date. |
140 | 151 | if ( !is_null( $end_date ) ) { |
141 | | - $end_date_jd = $end_date->getDataItem()->getSerialization(); |
| 152 | + $end_date_jd = $end_date->getDataItem()->getJD(); |
142 | 153 | } |
143 | 154 | |
144 | 155 | $cur_date = $start_date; |
145 | | - $cur_date_jd = $start_date->getDataItem()->getSerialization(); |
| 156 | + $cur_date_jd = $start_date->getDataItem()->getJD(); |
146 | 157 | $i = 0; |
147 | 158 | $reached_end_date = false; |
148 | 159 | |
— | — | @@ -190,7 +201,7 @@ |
191 | 202 | // keep incrementing by a week, until we get there. |
192 | 203 | do { |
193 | 204 | $cur_date_jd += 7; |
194 | | - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd ); |
| 205 | + $cur_date = self::jdToTimeValue( $cur_date_jd ); |
195 | 206 | $right_month = ( $cur_date->getMonth() == $new_month ); |
196 | 207 | |
197 | 208 | if ( $week_num < 0 ) { |
— | — | @@ -198,19 +209,19 @@ |
199 | 210 | |
200 | 211 | do { |
201 | 212 | $next_week_jd += 7; |
202 | | - $next_week_date = SMWDataValueFactory::newTypeIDValue( '_dat', $next_week_jd ); |
| 213 | + $next_week_date = self::jdToTimeValue( $next_week_jd ); |
203 | 214 | $right_week = ( $next_week_date->getMonth() != $new_month ) || ( $next_week_date->getYear() != $new_year ); |
204 | 215 | } while ( !$right_week ); |
205 | 216 | |
206 | 217 | $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 ); |
208 | 219 | } else { |
209 | 220 | $cur_week_num = ceil( $cur_date->getDay() / 7 ); |
210 | 221 | $right_week = ( $cur_week_num == $week_num ); |
211 | 222 | |
212 | 223 | if ( $week_num == 5 && ( $cur_date->getMonth() % 12 == ( $new_month + 1 ) % 12 ) ) { |
213 | 224 | $cur_date_jd -= 7; |
214 | | - $cur_date = SMWDataValueFactory::newTypeIDValue( '_dat', $cur_date_jd ); |
| 225 | + $cur_date = self::jdToTimeValue( $cur_date_jd ); |
215 | 226 | $right_month = $right_week = true; |
216 | 227 | } |
217 | 228 | } |
— | — | @@ -218,7 +229,7 @@ |
219 | 230 | } else { // $unit == 'day' or 'week' |
220 | 231 | // Assume 'day' if it's none of the above. |
221 | 232 | $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 ); |
223 | 234 | } |
224 | 235 | |
225 | 236 | // should we stop? |
— | — | @@ -237,4 +248,4 @@ |
238 | 249 | return array( $property_name, $all_date_strings, $unused_params ); |
239 | 250 | } |
240 | 251 | |
241 | | -} |
\ No newline at end of file |
| 252 | +} |