24use Wikimedia\Timestamp\ConvertibleTimestamp;
40 return new static( $ts );
64 if (
$lang ===
null ) {
65 $lang = RequestContext::getMain()->getLanguage();
68 return $lang->getHumanTimestamp( $this, $relativeTo, $user );
82 $option = $user->
getOption(
'timecorrection' );
83 $data = explode(
'|', $option, 3 );
86 if ( $data[0] ==
'ZoneInfo' ) {
88 $tz =
new DateTimeZone( $data[2] );
89 }
catch ( Exception $e ) {
94 $this->timestamp->setTimezone( $tz );
95 return new DateInterval(
'P0Y' );
104 if ( $data[0] ==
'System' ) {
109 } elseif ( $data[0] ==
'Offset' ) {
111 $diff = (int)$data[1];
115 $data = explode(
':', $option );
116 if ( count( $data ) >= 2 ) {
118 $diff = abs( (
int)$data[0] ) * 60 + (int)$data[1];
119 if ( (
int)$data[0] < 0 ) {
124 $diff = (int)$data[0] * 60;
128 $interval =
new DateInterval(
'PT' . abs( $diff ) .
'M' );
130 $interval->invert = 1;
133 $this->timestamp->add( $interval );
151 array $chosenIntervals = []
153 if ( $relativeTo ===
null ) {
154 $relativeTo =
new self;
156 if ( $user ===
null ) {
157 $user = RequestContext::getMain()->getUser();
159 if (
$lang ===
null ) {
160 $lang = RequestContext::getMain()->getLanguage();
164 $diff = $this->diff( $relativeTo );
166 'GetRelativeTimestamp',
167 [ &$ts, &$diff, $this, $relativeTo, $user,
$lang ]
169 $seconds = ( ( ( $diff->days * 24 + $diff->h ) * 60 + $diff->i ) * 60 + $diff->s );
170 $ts =
wfMessage(
'ago',
$lang->formatDuration( $seconds, $chosenIntervals ) )
171 ->inLanguage(
$lang )->text();
187 $tzMsg = $this->format(
'T' );
188 $key =
'timezone-' . strtolower( trim( $tzMsg ) );
190 if ( $msg->exists() ) {
206 $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.
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