MediaWiki  master
MWTimestamp Class Reference

Library for creating and parsing MW-style timestamps. More...

Inheritance diagram for MWTimestamp:
Collaboration diagram for MWTimestamp:

Public Member Functions

 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 timestamp and this object. More...
 
 getTimezoneMessage ()
 Get the localized timezone message, if available. More...
 
 offsetForUser (UserIdentity $user)
 Adjust the timestamp depending on the given user's preferences. More...
 

Static Public Member Functions

static getInstance ( $ts=false)
 Get a timestamp instance in GMT. More...
 
static getLocalInstance ( $ts=false)
 Get a timestamp instance in the server local timezone ($wgLocaltimezone) More...
 

Detailed Description

Library for creating and parsing MW-style timestamps.

Based on the JS library that does the same thing.

Stability: newable
Since
1.20

Definition at line 41 of file MWTimestamp.php.

Member Function Documentation

◆ getInstance()

static MWTimestamp::getInstance (   $ts = false)
static

Get a timestamp instance in GMT.

Parameters
bool | string$tsTimestamp to set, or false for current time
Returns
MWTimestamp The instance

Definition at line 48 of file MWTimestamp.php.

Referenced by Xml\dateMenu(), MediaWiki\Specials\SpecialLog\execute(), WikiBirthday\execute(), RangeChronologicalPager\getDateRangeCond(), ReverseChronologicalPager\getOffsetDate(), and FileRepo\storeTemp().

◆ getLocalInstance()

static MWTimestamp::getLocalInstance (   $ts = false)
static

Get a timestamp instance in the server local timezone ($wgLocaltimezone)

Since
1.22
Parameters
bool | string$tsTimestamp to set, or false for current time
Returns
MWTimestamp The local instance

Definition at line 142 of file MWTimestamp.php.

Referenced by SpecialVersion\getCopyrightAndAuthorList(), RevertAction\getFormFields(), and UserMailer\sendInternal().

◆ getRelativeTimestamp()

MWTimestamp::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 timestamp and this object.

Parameters
MWTimestamp | null$relativeToRelative base timestamp (defaults to now)
UserIdentity | null$userUse to use offset for
Language | null$langLanguage to use
array$chosenIntervalsIntervals to use to represent it
Returns
string Relative timestamp

Definition at line 90 of file MWTimestamp.php.

References $lang, RequestContext\getMain(), User\newFromIdentity(), and wfMessage().

◆ getTimezoneMessage()

MWTimestamp::getTimezoneMessage ( )

Get the localized timezone message, if available.

Premade translations are not shipped as format() may return whatever the system uses, localized or not, so translation must be done through wiki.

Since
1.27
Returns
Message The localized timezone message

Definition at line 124 of file MWTimestamp.php.

References wfMessage().

◆ offsetForUser()

MWTimestamp::offsetForUser ( UserIdentity  $user)

Adjust the timestamp depending on the given user's preferences.

Since
1.22
Parameters
UserIdentity$userUser to take preferences from
Returns
DateInterval Offset that was applied to the timestamp

Definition at line 60 of file MWTimestamp.php.

Referenced by Language\getHumanTimestamp().


The documentation for this class was generated from the following file: