Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -1986,6 +1986,8 @@ |
1987 | 1987 | function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) { |
1988 | 1988 | $uts = 0; |
1989 | 1989 | $da = array(); |
| 1990 | + $strtime = ''; |
| 1991 | + |
1990 | 1992 | if ( $ts === 0 ) { |
1991 | 1993 | $uts = time(); |
1992 | 1994 | } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) { |
— | — | @@ -1997,10 +1999,11 @@ |
1998 | 2000 | } elseif ( preg_match( '/^-?\d{1,13}$/D', $ts ) ) { |
1999 | 2001 | # TS_UNIX |
2000 | 2002 | $uts = $ts; |
| 2003 | + $strtime = "@$ts"; // Undocumented? |
2001 | 2004 | } elseif ( preg_match( '/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}.\d{6}$/', $ts ) ) { |
2002 | 2005 | # TS_ORACLE // session altered to DD-MM-YYYY HH24:MI:SS.FF6 |
2003 | | - $uts = strtotime( preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3", |
2004 | | - str_replace( '+00:00', 'UTC', $ts ) ) ); |
| 2006 | + $strtime = preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3", |
| 2007 | + str_replace( '+00:00', 'UTC', $ts ) ); |
2005 | 2008 | } elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) { |
2006 | 2009 | # TS_ISO_8601 |
2007 | 2010 | } elseif ( preg_match( '/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) { |
— | — | @@ -2013,19 +2016,14 @@ |
2014 | 2017 | # TS_DB2 |
2015 | 2018 | } elseif ( preg_match( '/^[A-Z][a-z]{2}, \d\d [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d/', $ts ) ) { |
2016 | 2019 | # TS_RFC2822 |
2017 | | - $uts = strtotime( $ts ); |
| 2020 | + $strtime = $ts; |
2018 | 2021 | } else { |
2019 | 2022 | # Bogus value; fall back to the epoch... |
2020 | 2023 | wfDebug("wfTimestamp() fed bogus time value: $outputtype; $ts\n"); |
2021 | 2024 | $uts = 0; |
2022 | 2025 | } |
2023 | 2026 | |
2024 | | - if (count( $da ) ) { |
2025 | | - // Warning! gmmktime() acts oddly if the month or day is set to 0 |
2026 | | - // We may want to handle that explicitly at some point |
2027 | | - $uts = gmmktime( (int)$da[4], (int)$da[5], (int)$da[6], |
2028 | | - (int)$da[2], (int)$da[3], (int)$da[1] ); |
2029 | | - } |
| 2027 | + |
2030 | 2028 | |
2031 | 2029 | static $formats = array( |
2032 | 2030 | TS_UNIX => 'U', |
— | — | @@ -2044,12 +2042,37 @@ |
2045 | 2043 | throw new MWException( 'wfTimestamp() called with illegal output type.' ); |
2046 | 2044 | } |
2047 | 2045 | |
2048 | | - if ( TS_UNIX == $outputtype ) { |
2049 | | - return $uts; |
| 2046 | + if ( function_exists( "date_create" ) ) { |
| 2047 | + if ( count( $da ) ) { |
| 2048 | + $ds = sprintf("%04d-%02d-%02dT%02d:%02d:%02d.00+00:00", |
| 2049 | + (int)$da[1], (int)$da[2], (int)$da[3], |
| 2050 | + (int)$da[4], (int)$da[5], (int)$da[6]); |
| 2051 | + |
| 2052 | + $d = date_create( $ds, new DateTimeZone( 'GMT' ) ); |
| 2053 | + } else { |
| 2054 | + $d = date_create( $strtime, new DateTimeZone( 'GMT' ) ); |
| 2055 | + } |
| 2056 | + $output = $d->format( $formats[$outputtype] ); |
| 2057 | + } else { |
| 2058 | + if ( count( $da ) ) { |
| 2059 | + // Warning! gmmktime() acts oddly if the month or day is set to 0 |
| 2060 | + // We may want to handle that explicitly at some point |
| 2061 | + $uts = gmmktime( (int)$da[4], (int)$da[5], (int)$da[6], |
| 2062 | + (int)$da[2], (int)$da[3], (int)$da[1] ); |
| 2063 | + } elseif ( $strtime ) { |
| 2064 | + $uts = strtotime( $strtime ); |
| 2065 | + } |
| 2066 | + |
| 2067 | + if ( $uts === false ) { |
| 2068 | + return "Can't handle date"; |
| 2069 | + } |
| 2070 | + |
| 2071 | + if ( TS_UNIX == $outputtype ) { |
| 2072 | + return $uts; |
| 2073 | + } |
| 2074 | + $output = gmdate( $formats[$outputtype], $uts ); |
2050 | 2075 | } |
2051 | 2076 | |
2052 | | - $output = gmdate( $formats[$outputtype], $uts ); |
2053 | | - |
2054 | 2077 | if ( ( $outputtype == TS_RFC2822 ) || ( $outputtype == TS_POSTGRES ) ) { |
2055 | 2078 | $output .= ' GMT'; |
2056 | 2079 | } |