29use Wikimedia\Timestamp\ConvertibleTimestamp;
47 return new static( $ts );
72 if (
$lang ===
null ) {
73 $lang = RequestContext::getMain()->getLanguage();
76 return $lang->getHumanTimestamp( $this, $relativeTo, $user );
88 $option = MediaWikiServices::getInstance()
89 ->getUserOptionsLookup()
90 ->getOption( $user,
'timecorrection' );
95 MediaWikiServices::getInstance()->getMainConfig()->
get( MainConfigNames::LocalTZoffset )
97 $tz = $value->getTimeZone();
99 $this->timestamp->setTimezone( $tz );
100 return new DateInterval(
'P0Y' );
102 $interval = $value->getTimeOffsetInterval();
103 $this->timestamp->add( $interval );
121 array $chosenIntervals = []
123 if ( $relativeTo ===
null ) {
124 $relativeTo =
new self;
126 if ( $user ===
null ) {
127 $user = RequestContext::getMain()->getUser();
129 if (
$lang ===
null ) {
130 $lang = RequestContext::getMain()->getLanguage();
134 $diff = $this->diff( $relativeTo );
137 if ( Hooks::runner()->onGetRelativeTimestamp(
138 $ts, $diff, $this, $relativeTo, $user,
$lang )
140 $seconds = ( ( ( $diff->days * 24 + $diff->h ) * 60 + $diff->i ) * 60 + $diff->s );
141 $ts =
wfMessage(
'ago',
$lang->formatDuration( $seconds, $chosenIntervals ) )
142 ->inLanguage(
$lang )->text();
158 $tzMsg = $this->format(
'T' );
159 $key =
'timezone-' . strtolower( trim( $tzMsg ) );
161 if ( $msg->exists() ) {
176 $localtimezone = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Localtimezone );
177 $timestamp =
new self( $ts );
178 $timestamp->setTimezone( $localtimezone );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
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)
getHumanTimestamp(MWTimestamp $relativeTo=null, UserIdentity $user=null, Language $lang=null)
Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
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.
Variant of the Message class.
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
if(!isset( $args[0])) $lang