MediaWiki  1.28.0
MWTimestamp Class Reference

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

Inheritance diagram for MWTimestamp:
Collaboration diagram for MWTimestamp:

Public Member Functions

 getHumanTimestamp (MWTimestamp $relativeTo=null, User $user=null, Language $lang=null)
 Get the timestamp in a human-friendly relative format, e.g., "3 days ago". More...
 
 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 timestamp and this object. More...
 
 getTimezoneMessage ()
 Get the localized timezone message, if available. More...
 
 offsetForUser (User $user)
 Adjust the timestamp depending on the given user's preferences. More...
 
- Public Member Functions inherited from ConvertibleTimestamp
 __construct ($timestamp=false)
 Make a new timestamp and set it to the specified time, or the current time if unspecified. More...
 
 __toString ()
 
 diff (ConvertibleTimestamp $relativeTo)
 Calculate the difference between two ConvertibleTimestamp objects. More...
 
 format ($format)
 Format the timestamp in a given format. More...
 
 getTimestamp ($style=TS_UNIX)
 Get the timestamp represented by this object in a certain form. More...
 
 getTimezone ()
 Get the timezone of this timestamp. More...
 
 setTimestamp ($ts=false)
 Set the timestamp to the specified time, or the current time if unspecified. More...
 
 setTimezone ($timezone)
 Set the timezone of this timestamp to the specified timezone. 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...
 
- Static Public Member Functions inherited from ConvertibleTimestamp
static convert ($style=TS_UNIX, $ts)
 Convert a timestamp string to a given format. More...
 
static now ($style=TS_MW)
 Get the current time in the given format. More...
 

Additional Inherited Members

- Public Attributes inherited from ConvertibleTimestamp
DateTime $timestamp
 The actual timestamp being wrapped (DateTime object). More...
 
- Static Public Attributes inherited from ConvertibleTimestamp
static TS_MW
 

Detailed Description

Library for creating and parsing MW-style timestamps.

Based on the JS library that does the same thing.

Since
1.20

Definition at line 31 of file MWTimestamp.php.

Member Function Documentation

MWTimestamp::getHumanTimestamp ( MWTimestamp  $relativeTo = null,
User  $user = null,
Language  $lang = null 
)

Get the timestamp in a human-friendly relative format, e.g., "3 days ago".

Determine the difference between the timestamp and the current time, and generate a readable timestamp by returning "<N> <units> ago", where the largest possible unit is used.

Since
1.20
1.22 Uses Language::getHumanTimestamp to produce the timestamp
Deprecated:
since 1.26 Use Language::getHumanTimestamp directly
Parameters
MWTimestamp | null$relativeToThe base timestamp to compare to (defaults to now)
User | null$userUser the timestamp is being generated for (or null to use main context's user)
Language | null$langLanguage to use to make the human timestamp (or null to use main context's language)
Returns
string Formatted timestamp

Definition at line 60 of file MWTimestamp.php.

References $lang, $user, and RequestContext\getMain().

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 38 of file MWTimestamp.php.

Referenced by Xml\dateMenu(), ReverseChronologicalPager\getDateCond(), Parser\getVariableValue(), FileRepo\storeTemp(), and ReverseChronologicalPagerTest\testGetDateCond().

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

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

Definition at line 146 of file MWTimestamp.php.

References $lang, $user, ConvertibleTimestamp\diff(), RequestContext\getMain(), Hooks\run(), and wfMessage().

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 185 of file MWTimestamp.php.

References ConvertibleTimestamp\format(), and wfMessage().

MWTimestamp::offsetForUser ( User  $user)

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

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

Definition at line 78 of file MWTimestamp.php.

References $e, $wgLocalTZoffset, User\getOption(), and global.

Referenced by Language\getHumanTimestamp().


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