MediaWiki
master
|
Library for creating and parsing MW-style timestamps. More...
Public Member Functions | |
__construct ($timestamp=false) | |
Make a new timestamp and set it to the specified time, or the current time if unspecified. More... | |
__toString () | |
diff (MWTimestamp $relativeTo) | |
Calculate the difference between two MWTimestamp objects. More... | |
format ($format) | |
Format the timestamp in a given format. More... | |
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... | |
getTimestamp ($style=TS_UNIX) | |
Get the timestamp represented by this object in a certain form. More... | |
getTimezone () | |
Get the timezone of this timestamp. More... | |
getTimezoneMessage () | |
Get the localized timezone message, if available. More... | |
offsetForUser (User $user) | |
Adjust the timestamp depending on the given user's preferences. 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... | |
Public Attributes | |
DateTime | $timestamp |
The actual timestamp being wrapped (DateTime object). More... | |
Static Public Attributes | |
static | TS_MW |
Static Private Attributes | |
static | $formats |
Standard gmdate() formats for the different timestamp types. More... | |
Library for creating and parsing MW-style timestamps.
Based on the JS library that does the same thing.
Definition at line 31 of file MWTimestamp.php.
MWTimestamp::__construct | ( | $timestamp = false | ) |
Make a new timestamp and set it to the specified time, or the current time if unspecified.
bool | string | int | float | $timestamp | Timestamp to set, or false for current time |
Definition at line 61 of file MWTimestamp.php.
References $timestamp, and setTimestamp().
MWTimestamp::__toString | ( | ) |
MWTimestamp::diff | ( | MWTimestamp | $relativeTo | ) |
Calculate the difference between two MWTimestamp objects.
MWTimestamp | $relativeTo | Base time to calculate difference from |
Definition at line 345 of file MWTimestamp.php.
Referenced by Language\getHumanTimestampInternal(), and getRelativeTimestamp().
MWTimestamp::format | ( | $format | ) |
Format the timestamp in a given format.
string | $format | Pattern to format in |
Definition at line 401 of file MWTimestamp.php.
Referenced by Language\getHumanTimestampInternal(), and getTimezoneMessage().
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.
MWTimestamp | null | $relativeTo | The base timestamp to compare to (defaults to now) |
User | null | $user | User the timestamp is being generated for (or null to use main context's user) |
Language | null | $lang | Language to use to make the human timestamp (or null to use main context's language) |
Definition at line 212 of file MWTimestamp.php.
References $lang, $user, and RequestContext\getMain().
|
static |
Get a timestamp instance in GMT.
bool | string | $ts | Timestamp to set, or false for current time |
Definition at line 426 of file MWTimestamp.php.
Referenced by Xml\dateMenu(), ReverseChronologicalPager\getDateCond(), Parser\getVariableValue(), and FileRepo\storeTemp().
|
static |
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
bool | string | $ts | Timestamp to set, or false for current time |
Definition at line 412 of file MWTimestamp.php.
References $timestamp, $wgLocaltimezone, and global.
Referenced by DatabaseOracle\doQuery(), SpecialVersion\getCopyrightAndAuthorList(), RevertAction\getFormFields(), Preferences\getTimezoneOptions(), Parser\getVariableValue(), HistoryAction\onView(), Parser\pstPass2(), CoreParserFunctions\revisionday(), CoreParserFunctions\revisionday2(), CoreParserFunctions\revisionmonth(), CoreParserFunctions\revisionmonth1(), CoreParserFunctions\revisiontimestamp(), CoreParserFunctions\revisionyear(), and UserMailer\sendInternal().
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.
MWTimestamp | $relativeTo | Relative base timestamp (defaults to now) |
User | $user | Use to use offset for |
Language | $lang | Language to use |
array | $chosenIntervals | Intervals to use to represent it |
Definition at line 298 of file MWTimestamp.php.
References $lang, $user, diff(), RequestContext\getMain(), Hooks\run(), and wfMessage().
MWTimestamp::getTimestamp | ( | $style = TS_UNIX | ) |
Get the timestamp represented by this object in a certain form.
Convert the internal timestamp to the specified format and then return it.
int | $style | Constant Output format for timestamp |
TimestampException |
Definition at line 175 of file MWTimestamp.php.
References $output, TS_MW, TS_POSTGRES, and TS_RFC2822.
Referenced by __toString(), and Language\getHumanTimestampInternal().
MWTimestamp::getTimezone | ( | ) |
Get the timezone of this timestamp.
Definition at line 370 of file MWTimestamp.php.
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.
Definition at line 383 of file MWTimestamp.php.
References format(), and wfMessage().
MWTimestamp::offsetForUser | ( | User | $user | ) |
Adjust the timestamp depending on the given user's preferences.
Definition at line 230 of file MWTimestamp.php.
References $e, $wgLocalTZoffset, User\getOption(), and global.
Referenced by Language\getHumanTimestamp().
MWTimestamp::setTimestamp | ( | $ts = false | ) |
Set the timestamp to the specified time, or the current time if unspecified.
Parse the given timestamp into either a DateTime object or a Unix timestamp, and then store it.
string | bool | $ts | Timestamp to store, or false for now |
TimestampException |
Definition at line 76 of file MWTimestamp.php.
Referenced by __construct().
MWTimestamp::setTimezone | ( | $timezone | ) |
Set the timezone of this timestamp to the specified timezone.
string | $timezone | Timezone to set |
TimestampException |
Definition at line 356 of file MWTimestamp.php.
References $e.
|
staticprivate |
Standard gmdate() formats for the different timestamp types.
Definition at line 35 of file MWTimestamp.php.
DateTime MWTimestamp::$timestamp |
The actual timestamp being wrapped (DateTime object).
Definition at line 51 of file MWTimestamp.php.
Referenced by __construct(), and getLocalInstance().
|
static |
Definition at line 37 of file MWTimestamp.php.
Referenced by getTimestamp().