Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php |
— | — | @@ -217,45 +217,47 @@ |
218 | 218 | $unclearparts = array(); |
219 | 219 | $prevmatchwasnumber = $matchisnumber = false; // used for looking back; numbers are days/months/years by default but may be re-interpreted if certain further symbols are found |
220 | 220 | $prevmatchwasdate = $matchisdate = false; // used for ensuring that date parts are in one block |
| 221 | + |
221 | 222 | foreach ( $matches as $match ) { |
222 | 223 | $prevmatchwasnumber = $matchisnumber; |
223 | 224 | $prevmatchwasdate = $matchisdate; |
224 | 225 | $matchisnumber = $matchisdate = false; |
| 226 | + |
225 | 227 | if ( $match == ' ' ) { |
226 | 228 | $matchisdate = $prevmatchwasdate; // spaces in dates do not end the date |
227 | 229 | } elseif ( $match == '-' ) { // can only occur separately between date components |
228 | 230 | $datecomponents[] = $match; // we check later if this makes sense |
229 | 231 | $matchisdate = true; |
230 | 232 | } elseif ( is_numeric( $match ) && |
231 | | - ( $prevmatchwasdate || ( count( $datecomponents ) == 0 ) ) ) { |
| 233 | + ( $prevmatchwasdate || count( $datecomponents ) == 0 ) ) { |
232 | 234 | $datecomponents[] = $match; |
233 | 235 | $matchisnumber = true; |
234 | 236 | $matchisdate = true; |
235 | | - } elseif ( ( $era === false ) && ( in_array( $match, array( 'AD', 'CE' ) ) ) ) { |
| 237 | + } elseif ( $era === false && in_array( $match, array( 'AD', 'CE' ) ) ) { |
236 | 238 | $era = '+'; |
237 | | - } elseif ( ( $era === false ) && ( in_array( $match, array( 'BC', 'BCE' ) ) ) ) { |
| 239 | + } elseif ( $era === false && in_array( $match, array( 'BC', 'BCE' ) ) ) { |
238 | 240 | $era = '-'; |
239 | | - } elseif ( ( $calendarmodel === false ) && ( in_array( $match, array( 'Gr', 'He', 'Jl', 'MJD', 'JD', 'OS' ) ) ) ) { |
| 241 | + } elseif ( $calendarmodel === false && in_array( $match, array( 'Gr', 'He', 'Jl', 'MJD', 'JD', 'OS' ) ) ) { |
240 | 242 | $calendarmodel = $match; |
241 | | - } elseif ( ( $ampm === false ) && ( ( strtolower( $match ) == 'am' ) || ( strtolower( $match ) == 'pm' ) ) ) { |
| 243 | + } elseif ( $ampm === false && ( strtolower( $match ) === 'am' || strtolower( $match ) === 'pm' ) ) { |
242 | 244 | $ampm = strtolower( $match ); |
243 | | - } elseif ( ( $hours === false ) && ( self::parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) ) { |
| 245 | + } elseif ( $hours === false && self::parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) { |
244 | 246 | // nothing to do |
245 | | - } elseif ( ( $hours === true ) && ( $timezoneoffset === false ) && |
246 | | - ( array_key_exists( $match, self::$m_tz ) ) ) { |
| 247 | + } elseif ( $hours !== false && $timezoneoffset === false && |
| 248 | + array_key_exists( $match, self::$m_tz ) ) { |
247 | 249 | // only accept timezone if time has already been set |
248 | 250 | $timezoneoffset = self::$m_tz[ $match ]; |
249 | | - } elseif ( ( $prevmatchwasnumber ) && ( $hours === false ) && ( $timezoneoffset === false ) && |
250 | | - ( array_key_exists( $match, self::$m_miltz ) ) && |
251 | | - ( self::parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) ) { |
| 251 | + } elseif ( $prevmatchwasnumber && $hours === false && $timezoneoffset === false && |
| 252 | + array_key_exists( $match, self::$m_miltz ) && |
| 253 | + self::parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) { |
252 | 254 | // military timezone notation is found after a number -> re-interpret the number as military time |
253 | 255 | array_pop( $datecomponents ); |
254 | 256 | $timezoneoffset = self::$m_miltz[ $match ]; |
255 | | - } elseif ( ( $prevmatchwasdate || ( count( $datecomponents ) == 0 ) ) && |
| 257 | + } elseif ( ( $prevmatchwasdate || count( $datecomponents ) == 0 ) && |
256 | 258 | $this->parseMonthString( $match, $monthname ) ) { |
257 | 259 | $datecomponents[] = $monthname; |
258 | 260 | $matchisdate = true; |
259 | | - } elseif ( $prevmatchwasnumber && $prevmatchwasdate && ( in_array( $match, array( 'st', 'nd', 'rd', 'th' ) ) ) ) { |
| 261 | + } elseif ( $prevmatchwasnumber && $prevmatchwasdate && in_array( $match, array( 'st', 'nd', 'rd', 'th' ) ) ) { |
260 | 262 | $datecomponents[] = 'd' . strval( array_pop( $datecomponents ) ); // must be a day; add standard marker |
261 | 263 | $matchisdate = true; |
262 | 264 | } else { |
— | — | @@ -269,21 +271,24 @@ |
270 | 272 | // debug_zval_dump( $unclearparts ); |
271 | 273 | |
272 | 274 | // Abort if we found unclear or over-specific information: |
273 | | - if ( ( count( $unclearparts ) != 0 ) || |
274 | | - ( ( $timezoneoffset !== false ) && ( $timeoffset !== false ) ) ) { |
| 275 | + if ( count( $unclearparts ) != 0 || |
| 276 | + ( $timezoneoffset !== false && $timeoffset !== false ) ) { |
275 | 277 | $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) ); |
276 | 278 | return false; |
277 | 279 | } |
| 280 | + |
278 | 281 | $timeoffset = $timeoffset + $timezoneoffset; |
279 | 282 | // Check if the a.m. and p.m. information is meaningful |
280 | | - if ( ( $ampm !== false ) && ( ( $hours > 12 ) || ( $hours == 0 ) ) ) { // Note: the == 0 check subsumes $hours===false |
| 283 | + |
| 284 | + if ( $ampm !== false && ( $hours > 12 || $hours == 0 ) ) { // Note: the == 0 check subsumes $hours===false |
281 | 285 | $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) ); |
282 | 286 | return false; |
283 | | - } elseif ( ( $ampm == 'am' ) && ( $hours == 12 ) ) { |
| 287 | + } elseif ( $ampm == 'am' && $hours == 12 ) { |
284 | 288 | $hours = 0; |
285 | | - } elseif ( ( $ampm == 'pm' ) && ( $hours < 12 ) ) { |
| 289 | + } elseif ( $ampm == 'pm' && $hours < 12 ) { |
286 | 290 | $hours += 12; |
287 | 291 | } |
| 292 | + |
288 | 293 | return true; |
289 | 294 | } |
290 | 295 | |