Index: trunk/extensions/ParserFunctions/ParserFunctions.php |
— | — | @@ -409,22 +409,32 @@ |
410 | 410 | $invalidTime = false; |
411 | 411 | |
412 | 412 | if ( class_exists( 'DateTime' ) ) { #PHP >= 5.2 |
413 | | - try { #the DateTime constructor must be used because it throws exceptions when errors occur, whereas date_create appears to just output a warning that can't really be detected from within the code |
414 | | - if ( $date !== '' ) { |
415 | | - $dateObject = new DateTime( $date ); |
| 413 | + # the DateTime constructor must be used because it throws exceptions |
| 414 | + # when errors occur, whereas date_create appears to just output a warning |
| 415 | + # that can't really be detected from within the code |
| 416 | + try { |
| 417 | + # Determine timezone |
| 418 | + if ( $local ) { |
| 419 | + # convert to MediaWiki local timezone if set |
| 420 | + if ( isset( $wgLocaltimezone ) ) { |
| 421 | + $tz = new DateTimeZone( $wgLocaltimezone ); |
| 422 | + } else { |
| 423 | + $tz = new DateTimeZone( 'UTC' ); |
| 424 | + } |
416 | 425 | } else { |
417 | | - $dateObject = new DateTime(); #use current date and time |
| 426 | + # if local time was not requested, convert to UTC |
| 427 | + $tz = new DateTimeZone( 'UTC' ); |
418 | 428 | } |
419 | | - |
420 | | - if ( $local ) { |
421 | | - if ( isset( $wgLocaltimezone ) ) { #convert to MediaWiki local timezone if set |
422 | | - $dateObject->setTimeZone( new DateTimeZone( $wgLocaltimezone ) ); |
423 | | - } #otherwise leave in PHP default |
| 429 | + |
| 430 | + # Parse date |
| 431 | + if ( $date !== '' ) { |
| 432 | + $dateObject = new DateTime( $date, $tz ); |
424 | 433 | } else { |
425 | | - #if local time was not requested, convert to UTC |
426 | | - $dateObject->setTimeZone( new DateTimeZone( 'UTC' ) ); |
| 434 | + # use current date and time |
| 435 | + $dateObject = new DateTime( 'now', $tz ); |
427 | 436 | } |
428 | | - |
| 437 | + |
| 438 | + # Generate timestamp |
429 | 439 | $ts = $dateObject->format( 'YmdHis' ); |
430 | 440 | } catch (Exception $ex) { |
431 | 441 | $invalidTime = true; |