X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FMWTimestamp.php;h=ad3228d9a0acbf0ce3609c686da503adf5ad32e1;hb=d302f3eed6516c6296ecc92d1774762c46348fa6;hp=9de2c0ab6cf96499ce0ddc716d09747e7f554b7b;hpb=96603cd221051a324c902b6d4debd88ff1418404;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MWTimestamp.php b/includes/MWTimestamp.php index 9de2c0ab6c..ad3228d9a0 100644 --- a/includes/MWTimestamp.php +++ b/includes/MWTimestamp.php @@ -77,7 +77,8 @@ class MWTimestamp { $da = array(); $strtime = ''; - if ( !$ts || $ts === "\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ) { // We want to catch 0, '', null... but not date strings starting with a letter. + // We want to catch 0, '', null... but not date strings starting with a letter. + if ( !$ts || $ts === "\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ) { $uts = time(); $strtime = "@$uts"; } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) { @@ -93,18 +94,41 @@ class MWTimestamp { # TS_ORACLE // session altered to DD-MM-YYYY HH24:MI:SS.FF6 $strtime = preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3", str_replace( '+00:00', 'UTC', $ts ) ); - } elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z?$/', $ts, $da ) ) { + } 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 ) ) { + } elseif ( preg_match( + '/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z?$/', + $ts, + $da + ) ) { #TS_ISO_8601_BASIC - } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) { + } elseif ( preg_match( + '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', + $ts, + $da + ) ) { # TS_POSTGRES - } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', $ts, $da ) ) { + } elseif ( preg_match( + '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', + $ts, + $da + ) ) { # TS_POSTGRES - } elseif ( preg_match( '/^[ \t\r\n]*([A-Z][a-z]{2},[ \t\r\n]*)?' . # Day of week - '\d\d?[ \t\r\n]*[A-Z][a-z]{2}[ \t\r\n]*\d{2}(?:\d{2})?' . # dd Mon yyyy - '[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d/S', $ts ) ) { # hh:mm:ss - # TS_RFC2822, accepting a trailing comment. See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html / r77171 + } elseif ( preg_match( + # Day of week + '/^[ \t\r\n]*([A-Z][a-z]{2},[ \t\r\n]*)?' . + # dd Mon yyyy + '\d\d?[ \t\r\n]*[A-Z][a-z]{2}[ \t\r\n]*\d{2}(?:\d{2})?' . + # hh:mm:ss + '[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d/S', + $ts + ) ) { + # TS_RFC2822, accepting a trailing comment. + # See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html / r77171 # The regex is a superset of rfc2822 for readability $strtime = strtok( $ts, ';' ); } elseif ( preg_match( '/^[A-Z][a-z]{5,8}, \d\d-[A-Z][a-z]{2}-\d{2} \d\d:\d\d:\d\d/', $ts ) ) { @@ -171,12 +195,17 @@ class MWTimestamp { * @since 1.20 * @since 1.22 Uses Language::getHumanTimestamp to produce the timestamp * - * @param MWTimestamp|null $relativeTo The base timestamp to compare to (defaults to now) - * @param User|null $user User the timestamp is being generated for (or null to use main context's user) - * @param Language|null $lang Language to use to make the human timestamp (or null to use main context's language) + * @param MWTimestamp|null $relativeTo The base timestamp to compare to + * (defaults to now). + * @param User|null $user User the timestamp is being generated for (or null + * to use main context's user). + * @param Language|null $lang Language to use to make the human timestamp + * (or null to use main context's language). * @return string Formatted timestamp */ - public function getHumanTimestamp( MWTimestamp $relativeTo = null, User $user = null, Language $lang = null ) { + public function getHumanTimestamp( MWTimestamp $relativeTo = null, + User $user = null, Language $lang = null + ) { if ( $relativeTo === null ) { $relativeTo = new self(); } @@ -239,7 +268,7 @@ class MWTimestamp { // first value. if ( $data[0] == 'System' ) { // First value is System, so use the system offset. - if ( isset( $wgLocalTZoffset ) ) { + if ( $wgLocalTZoffset !== null ) { $diff = $wgLocalTZoffset; } } elseif ( $data[0] == 'Offset' ) { @@ -298,11 +327,13 @@ class MWTimestamp { $ts = ''; $diff = $this->diff( $relativeTo ); - if ( wfRunHooks( 'GetRelativeTimestamp', array( &$ts, &$diff, $this, $relativeTo, $user, $lang ) ) ) { + if ( wfRunHooks( + 'GetRelativeTimestamp', + array( &$ts, &$diff, $this, $relativeTo, $user, $lang ) + ) ) { $seconds = ( ( ( $diff->days * 24 + $diff->h ) * 60 + $diff->i ) * 60 + $diff->s ); $ts = wfMessage( 'ago', $lang->formatDuration( $seconds, $chosenIntervals ) ) - ->inLanguage( $lang ) - ->text(); + ->inLanguage( $lang )->text(); } return $ts; @@ -322,7 +353,8 @@ class MWTimestamp { * * @since 1.22 * @param MWTimestamp $relativeTo Base time to calculate difference from - * @return DateInterval|bool The DateInterval object representing the difference between the two dates or false on failure + * @return DateInterval|bool The DateInterval object representing the + * difference between the two dates or false on failure */ public function diff( MWTimestamp $relativeTo ) { return $this->timestamp->diff( $relativeTo->timestamp ); @@ -332,7 +364,7 @@ class MWTimestamp { * Set the timezone of this timestamp to the specified timezone. * * @since 1.22 - * @param String $timezone Timezone to set + * @param string $timezone Timezone to set * @throws TimestampException */ public function setTimezone( $timezone ) {