MediaWiki  master
ConvertibleTimestamp Class Reference

Library for creating, parsing, and converting timestamps. More...

Inheritance diagram for ConvertibleTimestamp:
Collaboration diagram for ConvertibleTimestamp:

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 (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 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...
 

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

Detailed Description

Library for creating, parsing, and converting timestamps.

Based on the JS library that does the same thing.

Since
1.28

Definition at line 31 of file ConvertibleTimestamp.php.

Constructor & Destructor Documentation

ConvertibleTimestamp::__construct (   $timestamp = false)

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

Parameters
bool | string | int | float | DateTime$timestampTimestamp to set, or false for current time

Definition at line 59 of file ConvertibleTimestamp.php.

References $timestamp, and setTimestamp().

Member Function Documentation

ConvertibleTimestamp::__toString ( )
Returns
string

Definition at line 222 of file ConvertibleTimestamp.php.

References getTimestamp().

static ConvertibleTimestamp::convert (   $style = TS_UNIX,
  $ts 
)
static

Convert a timestamp string to a given format.

Parameters
int$styleConstant Output format for timestamp
string$tsTimestamp
Returns
string|bool Formatted timestamp or false on failure

Definition at line 171 of file ConvertibleTimestamp.php.

References $e.

Referenced by Database\decodeExpiry(), FileBackendStore\setFileCache(), ConvertibleTimestampTest\testConvert(), ConvertibleTimestampTest\testConvertInvalid(), and XMPValidate\validateDate().

ConvertibleTimestamp::diff ( ConvertibleTimestamp  $relativeTo)

Calculate the difference between two ConvertibleTimestamp objects.

Parameters
ConvertibleTimestamp$relativeToBase time to calculate difference from
Returns
DateInterval|bool The DateInterval object representing the difference between the two dates or false on failure

Definition at line 233 of file ConvertibleTimestamp.php.

Referenced by Language\getHumanTimestampInternal(), and MWTimestamp\getRelativeTimestamp().

ConvertibleTimestamp::format (   $format)

Format the timestamp in a given format.

Parameters
string$formatPattern to format in
Returns
string The formatted timestamp

Definition at line 266 of file ConvertibleTimestamp.php.

Referenced by Language\getHumanTimestampInternal(), and MWTimestamp\getTimezoneMessage().

ConvertibleTimestamp::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.

Parameters
int$styleConstant Output format for timestamp
Exceptions
TimestampException
Returns
string The formatted timestamp

Definition at line 200 of file ConvertibleTimestamp.php.

References $output, TS_MW, TS_POSTGRES, and TS_RFC2822.

Referenced by __toString(), and Language\getHumanTimestampInternal().

ConvertibleTimestamp::getTimezone ( )

Get the timezone of this timestamp.

Returns
DateTimeZone The timezone

Definition at line 256 of file ConvertibleTimestamp.php.

static ConvertibleTimestamp::now (   $style = TS_MW)
static

Get the current time in the given format.

Parameters
int$styleConstant Output format for timestamp
Returns
string

Definition at line 186 of file ConvertibleTimestamp.php.

ConvertibleTimestamp::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.

Parameters
string | bool$tsTimestamp to store, or false for now
Exceptions
TimestampException

Definition at line 76 of file ConvertibleTimestamp.php.

References $e, of, and ss.

Referenced by __construct().

ConvertibleTimestamp::setTimezone (   $timezone)

Set the timezone of this timestamp to the specified timezone.

Parameters
string$timezoneTimezone to set
Exceptions
TimestampException

Definition at line 243 of file ConvertibleTimestamp.php.

References $e.

Member Data Documentation

ConvertibleTimestamp::$formats
staticprivate
Initial value:
= [
TS_UNIX => 'U'

Standard gmdate() formats for the different timestamp types.

Definition at line 35 of file ConvertibleTimestamp.php.

DateTime ConvertibleTimestamp::$timestamp

The actual timestamp being wrapped (DateTime object).

Definition at line 51 of file ConvertibleTimestamp.php.

Referenced by __construct(), and MWTimestamp\getLocalInstance().

ConvertibleTimestamp::TS_MW
static
Initial value:
=> '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',
]

Definition at line 37 of file ConvertibleTimestamp.php.

Referenced by getTimestamp().


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