Go to the documentation of this file.
27 use Wikimedia\Timestamp\ConvertibleTimestamp;
45 return new static( $ts );
69 if (
$lang ===
null ) {
73 return $lang->getHumanTimestamp( $this, $relativeTo, $user );
87 $option = MediaWikiServices::getInstance()
88 ->getUserOptionsLookup()
89 ->getOption( $user,
'timecorrection' );
91 $data = explode(
'|', $option, 3 );
94 if ( $data[0] ==
'ZoneInfo' ) {
96 $tz =
new DateTimeZone( $data[2] );
97 }
catch ( Exception $e ) {
102 $this->timestamp->setTimezone( $tz );
103 return new DateInterval(
'P0Y' );
112 if ( $data[0] ==
'System' ) {
117 } elseif ( $data[0] ==
'Offset' ) {
119 $diff = (int)$data[1];
123 $data = explode(
':', $option );
124 if ( count( $data ) >= 2 ) {
126 $diff = abs( (
int)$data[0] ) * 60 + (int)$data[1];
127 if ( (
int)$data[0] < 0 ) {
132 $diff = (int)$data[0] * 60;
136 $interval =
new DateInterval(
'PT' . abs( $diff ) .
'M' );
138 $interval->invert = 1;
141 $this->timestamp->add( $interval );
159 array $chosenIntervals = []
161 if ( $relativeTo ===
null ) {
162 $relativeTo =
new self;
164 if ( $user ===
null ) {
167 if (
$lang ===
null ) {
172 $diff = $this->diff( $relativeTo );
176 $ts, $diff, $this, $relativeTo, $user,
$lang )
178 $seconds = ( ( ( $diff->days * 24 + $diff->h ) * 60 + $diff->i ) * 60 + $diff->s );
179 $ts =
wfMessage(
'ago',
$lang->formatDuration( $seconds, $chosenIntervals ) )
180 ->inLanguage(
$lang )->text();
196 $tzMsg = $this->format(
'T' );
197 $key =
'timezone-' . strtolower( trim( $tzMsg ) );
199 if ( $msg->exists() ) {
215 $timestamp =
new self( $ts );
getTimezoneMessage()
Get the localized timezone message, if available.
Library for creating and parsing MW-style timestamps.
if(!isset( $args[0])) $lang
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
getRelativeTimestamp(MWTimestamp $relativeTo=null, UserIdentity $user=null, Language $lang=null, array $chosenIntervals=[])
Generate a purely relative timestamp, i.e., represent the time elapsed between the given base timesta...
static getInstance( $ts=false)
Get a timestamp instance in GMT.
$wgLocalTZoffset
Set an offset from UTC in minutes to use for the default timezone setting for anonymous users and new...
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
static getMain()
Get the RequestContext object associated with the main request.
getHumanTimestamp(MWTimestamp $relativeTo=null, UserIdentity $user=null, Language $lang=null)
Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
Variant of the Message class.
static getLocalInstance( $ts=false)
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
offsetForUser(UserIdentity $user)
Adjust the timestamp depending on the given user's preferences.