24use Wikimedia\Timestamp\ConvertibleTimestamp;
42 return new static( $ts );
66 if (
$lang ===
null ) {
67 $lang = RequestContext::getMain()->getLanguage();
70 return $lang->getHumanTimestamp( $this, $relativeTo, $user );
84 $option = $user->
getOption(
'timecorrection' );
85 $data = explode(
'|', $option, 3 );
88 if ( $data[0] ==
'ZoneInfo' ) {
90 $tz =
new DateTimeZone( $data[2] );
91 }
catch ( Exception $e ) {
96 $this->timestamp->setTimezone( $tz );
97 return new DateInterval(
'P0Y' );
106 if ( $data[0] ==
'System' ) {
111 } elseif ( $data[0] ==
'Offset' ) {
113 $diff = (int)$data[1];
117 $data = explode(
':', $option );
118 if ( count( $data ) >= 2 ) {
120 $diff = abs( (
int)$data[0] ) * 60 + (int)$data[1];
121 if ( (
int)$data[0] < 0 ) {
126 $diff = (int)$data[0] * 60;
130 $interval =
new DateInterval(
'PT' . abs( $diff ) .
'M' );
132 $interval->invert = 1;
135 $this->timestamp->add( $interval );
153 array $chosenIntervals = []
155 if ( $relativeTo ===
null ) {
156 $relativeTo =
new self;
158 if ( $user ===
null ) {
159 $user = RequestContext::getMain()->getUser();
161 if (
$lang ===
null ) {
162 $lang = RequestContext::getMain()->getLanguage();
166 $diff = $this->diff( $relativeTo );
167 if ( Hooks::runner()->onGetRelativeTimestamp(
168 $ts, $diff, $this, $relativeTo, $user,
$lang )
170 $seconds = ( ( ( $diff->days * 24 + $diff->h ) * 60 + $diff->i ) * 60 + $diff->s );
171 $ts =
wfMessage(
'ago',
$lang->formatDuration( $seconds, $chosenIntervals ) )
172 ->inLanguage(
$lang )->text();
188 $tzMsg = $this->format(
'T' );
189 $key =
'timezone-' . strtolower( trim( $tzMsg ) );
191 if ( $msg->exists() ) {
207 $timestamp =
new self( $ts );
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
$wgLocalTZoffset
Set an offset from UTC in minutes to use for the default timezone setting for anonymous users and new...
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Library for creating and parsing MW-style timestamps.
getRelativeTimestamp(MWTimestamp $relativeTo=null, User $user=null, Language $lang=null, array $chosenIntervals=[])
Generate a purely relative timestamp, i.e., represent the time elapsed between the given base timesta...
getHumanTimestamp(MWTimestamp $relativeTo=null, User $user=null, Language $lang=null)
Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
static getInstance( $ts=false)
Get a timestamp instance in GMT.
static getLocalInstance( $ts=false)
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
getTimezoneMessage()
Get the localized timezone message, if available.
offsetForUser(User $user)
Adjust the timestamp depending on the given user's preferences.
Variant of the Message class.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
if(!isset( $args[0])) $lang