X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FTimestamp.php;h=c1c64551e9114a8b43a9b0a06a185e6f23ceda9c;hb=aea3a5dce215b9f3929d65365fe9bd101ecdf07d;hp=48d972cebad7fd50ba6d440a10e6f998a15df263;hpb=3884fa4e5f5265565900f7058c52350c7a04f4f2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Timestamp.php b/includes/Timestamp.php index 48d972ceba..c1c64551e9 100644 --- a/includes/Timestamp.php +++ b/includes/Timestamp.php @@ -93,9 +93,9 @@ 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 ) ) { # TS_POSTGRES @@ -270,6 +270,44 @@ class MWTimestamp { return $interval; } + /** + * Generate a purely relative timestamp, i.e., represent the time elapsed between + * the given base timestamp and this object. + * + * @param MWTimestamp $relativeTo Relative base timestamp (defaults to now) + * @param User $user Use to use offset for + * @param Language $lang Language to use + * @param array $chosenIntervals Intervals to use to represent it + * @return string Relative timestamp + */ + public function getRelativeTimestamp( + MWTimestamp $relativeTo = null, + User $user = null, + Language $lang = null, + array $chosenIntervals = array() + ) { + if ( $relativeTo === null ) { + $relativeTo = new self; + } + if ( $user === null ) { + $user = RequestContext::getMain()->getUser(); + } + if ( $lang === null ) { + $lang = RequestContext::getMain()->getLanguage(); + } + + $ts = ''; + $diff = $this->diff( $relativeTo ); + 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(); + } + + return $ts; + } + /** * @since 1.20 *