Page MenuHomePhabricator
Authored By
bzimport
Nov 21 2014, 11:14 PM
Size
3 KB
Referenced Files
None
Subscribers
None
Index: mediawiki-trunk/includes/GlobalFunctions.php
===================================================================
--- mediawiki-trunk/includes/GlobalFunctions.php (revision 74803)
+++ mediawiki-trunk/includes/GlobalFunctions.php (working copy)
@@ -1976,6 +1976,7 @@
*/
function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
$uts = 0;
+ $ds = "";
$da = array();
if ( $ts === 0 ) {
$uts = time();
@@ -1987,11 +1988,14 @@
# TS_MW
} elseif ( preg_match( '/^-?\d{1,13}$/D', $ts ) ) {
# TS_UNIX
+ //XXX what about negative or 64-bit values?
$uts = $ts;
+ $ds = '@' . $ts;
} elseif ( preg_match( '/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}.\d{6}$/', $ts ) ) {
# TS_ORACLE // session altered to DD-MM-YYYY HH24:MI:SS.FF6
- $uts = strtotime( preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3",
- str_replace( '+00:00', 'UTC', $ts ) ) );
+ $ds = preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3",
+ str_replace( '+00:00', 'UTC', $ts ) );
+ $uts = strtotime($ds);
} elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
# TS_ISO_8601
} elseif ( preg_match( '/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
@@ -2005,6 +2009,7 @@
} elseif ( preg_match( '/^[A-Z][a-z]{2}, \d\d [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d/', $ts ) ) {
# TS_RFC2822
$uts = strtotime( $ts );
+ $ds = $ts;
} else {
# Bogus value; fall back to the epoch...
wfDebug("wfTimestamp() fed bogus time value: $outputtype; $ts\n");
@@ -2016,30 +2021,62 @@
// We may want to handle that explicitly at some point
$uts = gmmktime( (int)$da[4], (int)$da[5], (int)$da[6],
(int)$da[2], (int)$da[3], (int)$da[1] );
+ // explicitly specify time zone as +00:00 to get UTC
+ $ds = sprintf("%04d-%02d-%02dT%02d:%02d:%02d.00+00:00",
+ (int)$da[1], (int)$da[2], (int)$da[3],
+ (int)$da[4], (int)$da[5], (int)$da[6]);
}
+ if ($ds) {
+ try {
+ $dt = new DateTime($ds);
+ } catch (Exception $e) {
+ $ds = "";
+ }
+ }
switch( $outputtype ) {
case TS_UNIX:
+ if ($ds)
+ return $dt->format( 'U' );
return $uts;
case TS_MW:
+ if ($ds)
+ return $dt->format( 'YmdHis' );
return gmdate( 'YmdHis', $uts );
case TS_DB:
+ if ($ds)
+ return $dt->format( 'Y-m-d H:i:s' );
return gmdate( 'Y-m-d H:i:s', $uts );
case TS_ISO_8601:
+ if ($ds)
+ return $dt->format( 'Y-m-d\TH:i:s\Z' );
return gmdate( 'Y-m-d\TH:i:s\Z', $uts );
case TS_ISO_8601_BASIC:
+ if ($ds)
+ return $dt->format( 'Ymd\THis\Z' );
return gmdate( 'Ymd\THis\Z', $uts );
// This shouldn't ever be used, but is included for completeness
case TS_EXIF:
+ if ($ds)
+ return $dt->format( 'Y:m:d H:i:s' );
return gmdate( 'Y:m:d H:i:s', $uts );
case TS_RFC2822:
+ if ($ds)
+ return $dt->format( 'D, d M Y H:i:s' );
return gmdate( 'D, d M Y H:i:s', $uts ) . ' GMT';
case TS_ORACLE:
+ if ($ds)
+ return $dt->format( 'd-m-Y H:i:s.000000' );
+// return $dt->format( 'd-M-y h.i.s A' );
return gmdate( 'd-m-Y H:i:s.000000', $uts );
//return gmdate( 'd-M-y h.i.s A', $uts ) . ' +00:00';
case TS_POSTGRES:
+ if ($ds)
+ return $dt->format( 'Y-m-d H:i:s' );
return gmdate( 'Y-m-d H:i:s', $uts ) . ' GMT';
case TS_DB2:
+ if ($ds)
+ return $dt->format( 'Y-m-d H:i:s' );
return gmdate( 'Y-m-d H:i:s', $uts );
default:
throw new MWException( 'wfTimestamp() called with illegal output type.' );

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6599
Default Alt Text
x (3 KB)

Event Timeline