Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F4282
patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 9:55 PM
2014-11-21 21:55:01 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
patch
View Options
Index: ParserFunctions.php
===================================================================
--- ParserFunctions.php (revision 41831)
+++ ParserFunctions.php (working copy)
@@ -396,14 +396,18 @@
if ( isset( $this->mTimeCache[$format][$date][$local] ) ) {
return $this->mTimeCache[$format][$date][$local];
}
-
- if ( $date !== '' ) {
- $unix = @strtotime( $date );
- } else {
- $unix = time();
+
+ try {
+ if ( $date !== '' ) {
+ $dateObject = new DateTime( $date );
+ } else {
+ $dateObject = new DateTime(); #use current date and time
+ }
+ } catch (Exception $ex) {
+ $dateObject = false;
}
-
- if ( $unix == -1 || $unix == false ) {
+
+ if ( $dateObject === false ) {
wfLoadExtensionMessages( 'ParserFunctions' );
$result = '<strong class="error">' . wfMsgForContent( 'pfunc_time_error' ) . '</strong>';
} else {
@@ -413,20 +417,16 @@
return '<strong class="error">' . wfMsgForContent( 'pfunc_time_too_long' ) . '</strong>';
} else {
if ( $local ) {
- # Use the time zone
- if ( isset( $wgLocaltimezone ) ) {
- $oldtz = getenv( 'TZ' );
- putenv( 'TZ='.$wgLocaltimezone );
- }
- wfSuppressWarnings(); // E_STRICT system time bitching
- $ts = date( 'YmdHis', $unix );
- wfRestoreWarnings();
- if ( isset( $wgLocaltimezone ) ) {
- putenv( 'TZ='.$oldtz );
- }
+ if ( isset( $wgLocaltimezone ) ) { #convert to MediaWiki local timezone if set
+ $dateObject->setTimeZone( new DateTimeZone( $wgLocaltimezone ) );
+ } #otherwise leave in PHP default
} else {
- $ts = wfTimestamp( TS_MW, $unix );
+ #if local time was not requested, convert to UTC
+ $dateObject->setTimeZone( new DateTimeZone( 'UTC' ) );
}
+
+ $ts = $dateObject->format( 'YmdHis' );
+
if ( method_exists( $wgContLang, 'sprintfDate' ) ) {
$result = $wgContLang->sprintfDate( $format, $ts );
} else {
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3847
Default Alt Text
patch (1 KB)
Attached To
Mode
T13686: make #time work with pre-1970 dates
Attached
Detach File
Event Timeline
Log In to Comment