30use Wikimedia\Timestamp\ConvertibleTimestamp;
48 return new static( $ts );
60 $option = MediaWikiServices::getInstance()
61 ->getUserOptionsLookup()
62 ->getOption( $user,
'timecorrection' );
67 MediaWikiServices::getInstance()->getMainConfig()->
get( MainConfigNames::LocalTZoffset )
69 $tz = $value->getTimeZone();
71 $this->timestamp->setTimezone( $tz );
72 return new DateInterval(
'P0Y' );
74 $interval = $value->getTimeOffsetInterval();
75 $this->timestamp->add( $interval );
93 array $chosenIntervals = []
95 $relativeTo ??=
new self();
96 $user ??= RequestContext::getMain()->getUser();
97 $lang ??= RequestContext::getMain()->getLanguage();
100 $diff = $this->diff( $relativeTo );
103 if ( Hooks::runner()->onGetRelativeTimestamp(
104 $ts, $diff, $this, $relativeTo, $user,
$lang )
106 $seconds = ( ( ( $diff->days * 24 + $diff->h ) * 60 + $diff->i ) * 60 + $diff->s );
107 $ts =
wfMessage(
'ago',
$lang->formatDuration( $seconds, $chosenIntervals ) )
108 ->inLanguage(
$lang )->text();
124 $tzMsg = $this->format(
'T' );
125 $key =
'timezone-' . strtolower( trim( $tzMsg ) );
127 if ( $msg->exists() ) {
142 $localtimezone = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Localtimezone );
143 $timestamp =
new self( $ts );
144 $timestamp->setTimezone( $localtimezone );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Base class for language-specific code.
Library for creating and parsing MW-style timestamps.
offsetForUser(UserIdentity $user)
Adjust the timestamp depending on the given user's preferences.
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.
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...
A class containing constants representing the names of configuration variables.
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
if(!isset( $args[0])) $lang