MediaWiki  REL1_20
MWTimestamp Class Reference

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

List of all members.

Public Member Functions

 __construct ($timestamp=false)
 Make a new timestamp and set it to the specified time, or the current time if unspecified.
 __toString ()
 getHumanTimestamp ()
 Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
 getTimestamp ($style=TS_UNIX)
 Get the timestamp represented by this object in a certain form.
 setTimestamp ($ts=false)
 Set the timestamp to the specified time, or the current time if unspecified.

Private Attributes

string DateTime $timestamp
 The actual timestamp being wrapped.

Static Private Attributes

static $formats
 Standard gmdate() formats for the different timestamp types.
static $units
 Different units for human readable timestamps.

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 Timestamp.php.


Constructor & Destructor Documentation

MWTimestamp::__construct ( timestamp = false)

Make a new timestamp and set it to the specified time, or the current time if unspecified.

Parameters:
$timestampbool|string Timestamp to set, or false for current time

Definition at line 73 of file Timestamp.php.


Member Function Documentation

Returns:
string

Definition at line 223 of file Timestamp.php.

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.

Returns:
string Formatted timestamp

Definition at line 196 of file Timestamp.php.

Get the timestamp represented by this object in a certain form.

Convert the internal timestamp to the specified format and then return it.

Parameters:
$styleint Constant Output format for timestamp
Exceptions:
TimestampException
Returns:
string The formatted timestamp

Definition at line 164 of file Timestamp.php.

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.

Parameters:
$tsstring|bool Timestamp to store, or false for now
Exceptions:
TimestampException

Definition at line 86 of file Timestamp.php.


Member Data Documentation

MWTimestamp::$formats [static, private]
Initial value:
 array(
                TS_UNIX => 'U',
                TS_MW => 'YmdHis',
                TS_DB => 'Y-m-d H:i:s',
                TS_ISO_8601 => 'Y-m-d\TH:i:s\Z',
                TS_ISO_8601_BASIC => 'Ymd\THis\Z',
                TS_EXIF => 'Y:m:d H:i:s', 
                TS_RFC2822 => 'D, d M Y H:i:s',
                TS_ORACLE => 'd-m-Y H:i:s.000000', 
                TS_POSTGRES => 'Y-m-d H:i:s',
                TS_DB2 => 'Y-m-d H:i:s',
        )

Standard gmdate() formats for the different timestamp types.

Definition at line 35 of file Timestamp.php.

string DateTime MWTimestamp::$timestamp [private]

The actual timestamp being wrapped.

Either a DateTime object or a string with a Unix timestamp depending on PHP.

Definition at line 65 of file Timestamp.php.

MWTimestamp::$units [static, private]
Initial value:
 array(
                "milliseconds" => 1,
                "seconds" => 1000, 
                "minutes" => 60, 
                "hours" => 60, 
                "days" => 24 
        )

Different units for human readable timestamps.

See also:
MWTimestamp::getHumanTimestamp

Definition at line 52 of file Timestamp.php.


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