BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
MWTimestamp Class Reference

Public Member Functions

 __construct ($timestamp=false)
 
 setTimestamp ($ts=false)
 
 getTimestamp ($style=TS_UNIX)
 
 getHumanTimestamp (MWTimestamp $relativeTo=null, User $user=null, Language $lang=null)
 
 offsetForUser (User $user)
 
 getRelativeTimestamp (MWTimestamp $relativeTo=null, User $user=null, Language $lang=null, array $chosenIntervals=[])
 
 __toString ()
 
 diff (MWTimestamp $relativeTo)
 
 setTimezone ($timezone)
 
 getTimezone ()
 
 getTimezoneMessage ()
 
 format ($format)
 

Static Public Member Functions

static getLocalInstance ($ts=false)
 
static getInstance ($ts=false)
 

Public Attributes

 $timestamp
 

Static Public Attributes

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

Constructor & Destructor Documentation

MWTimestamp::__construct (   $timestamp = false)

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

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

Member Function Documentation

MWTimestamp::__toString ( )
Since
1.20
Returns
string
MWTimestamp::diff ( MWTimestamp  $relativeTo)

Calculate the difference between two MWTimestamp objects.

Since
1.22
Parameters
MWTimestamp$relativeToBase time to calculate difference from
Returns
DateInterval|bool The DateInterval object representing the difference between the two dates or false on failure
MWTimestamp::format (   $format)

Format the timestamp in a given format.

Since
1.22
Parameters
string$formatPattern to format in
Returns
string The formatted timestamp
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
static MWTimestamp::getInstance (   $ts = false)
static

Get a timestamp instance in GMT

Since
1.22
Parameters
bool | string$tsTimestamp to set, or false for current time
Returns
MWTimestamp The instance
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
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
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.

Since
1.20
Parameters
int$styleConstant Output format for timestamp
Exceptions
TimestampException
Returns
string The formatted timestamp
MWTimestamp::getTimezone ( )

Get the timezone of this timestamp.

Since
1.22
Returns
DateTimeZone The timezone
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
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
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.

Since
1.20
Parameters
string | bool$tsTimestamp to store, or false for now
Exceptions
TimestampException
MWTimestamp::setTimezone (   $timezone)

Set the timezone of this timestamp to the specified timezone.

Since
1.22
Parameters
string$timezoneTimezone to set
Exceptions
TimestampException

Member Data Documentation

MWTimestamp::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',
]

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