Go to the documentation of this file.
38 TS_DB =>
'Y-m-d H:i:s',
80 if ( !$ts || $ts ===
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ) {
83 } elseif ( preg_match(
'/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
85 } elseif ( preg_match(
'/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
87 } elseif ( preg_match(
'/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/D', $ts, $da ) ) {
89 } elseif ( preg_match(
'/^-?\d{1,13}$/D', $ts ) ) {
92 } elseif ( preg_match(
'/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}.\d{6}$/', $ts ) ) {
93 # TS_ORACLE // session altered to DD-MM-YYYY HH24:MI:SS.FF6
94 $strtime = preg_replace(
'/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/',
"$1:$2:$3",
95 str_replace(
'+00:00',
'UTC', $ts ) );
96 } elseif ( preg_match(
'/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z?$/', $ts, $da ) ) {
98 } elseif ( preg_match(
'/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z?$/', $ts, $da ) ) {
100 } elseif ( preg_match(
'/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) {
102 } elseif ( preg_match(
'/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', $ts, $da ) ) {
104 } elseif ( preg_match(
'/^[ \t\r\n]*([A-Z][a-z]{2},[ \t\r\n]*)?' . # Day
of week
105 '\d\d?[ \t\r\n]*[A-Z][a-z]{2}[ \t\r\n]*\d{2}(?:\d{2})?' . # dd Mon yyyy
106 '[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d/S', $ts ) ) { # hh:mm:ss
107 # TS_RFC2822, accepting a trailing comment. See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html / r77171
108 # The regex is a superset of rfc2822 for readability
109 $strtime = strtok( $ts,
';' );
110 } elseif ( preg_match(
'/^[A-Z][a-z]{5,8}, \d\d-[A-Z][a-z]{2}-\d{2} \d\d:\d\d:\d\d/', $ts ) ) {
113 } elseif ( preg_match(
'/^[A-Z][a-z]{2} [A-Z][a-z]{2} +\d{1,2} \d\d:\d\d:\d\d \d{4}/', $ts ) ) {
121 $da = array_map(
'intval', $da );
122 $da[0] =
"%04d-%02d-%02dT%02d:%02d:%02d.00+00:00";
123 $strtime = call_user_func_array(
"sprintf", $da );
127 $final =
new DateTime( $strtime,
new DateTimeZone(
'GMT' ) );
128 }
catch ( Exception
$e ) {
132 if ( $final ===
false ) {
135 $this->timestamp = $final;
151 if ( !isset( self::$formats[$style] ) ) {
155 $output = $this->timestamp->format( self::$formats[$style] );
180 if ( $relativeTo ===
null ) {
181 $relativeTo =
new self();
183 if (
$user ===
null ) {
186 if ( $lang ===
null ) {
192 $offsetRel = $relativeTo->offsetForUser(
$user );
196 $ts = $lang->getHumanTimestamp( $this, $relativeTo,
$user );
200 $this->timestamp->sub( $offsetThis );
201 $relativeTo->timestamp->sub( $offsetRel );
218 $option =
$user->getOption(
'timecorrection' );
219 $data = explode(
'|', $option, 3 );
222 if ( $data[0] ==
'ZoneInfo' ) {
224 $tz =
new DateTimeZone( $data[2] );
225 }
catch ( Exception
$e ) {
230 $this->timestamp->setTimezone( $tz );
231 return new DateInterval(
'P0Y' );
240 if ( $data[0] ==
'System' ) {
242 if ( isset( $wgLocalTZoffset ) ) {
243 $diff = $wgLocalTZoffset;
245 } elseif ( $data[0] ==
'Offset' ) {
247 $diff = (int)$data[1];
251 $data = explode(
':', $option );
252 if ( count( $data ) >= 2 ) {
254 $diff = abs( (
int)$data[0] ) * 60 + (int)$data[1];
255 if ( (
int)$data[0] < 0 ) {
260 $diff = (int)$data[0] * 60;
264 $interval =
new DateInterval(
'PT' . abs( $diff ) .
'M' );
266 $interval->invert = 1;
269 $this->timestamp->add( $interval );
289 if ( $relativeTo ===
null ) {
290 $relativeTo =
new self;
292 if (
$user ===
null ) {
295 if ( $lang ===
null ) {
300 $diff = $this->
diff( $relativeTo );
301 if (
wfRunHooks(
'GetRelativeTimestamp',
array( &$ts, &$diff, $this, $relativeTo,
$user, $lang ) ) ) {
302 $seconds = ( ( ( $diff->days * 24 + $diff->h ) * 60 + $diff->i ) * 60 + $diff->s );
303 $ts =
wfMessage(
'ago', $lang->formatDuration( $seconds, $chosenIntervals ) )
304 ->inLanguage( $lang )
328 return $this->timestamp->diff( $relativeTo->timestamp );
340 $this->timestamp->setTimezone(
new DateTimeZone( $timezone ) );
341 }
catch ( Exception
$e ) {
353 return $this->timestamp->getTimezone();
363 public function format( $format ) {
364 return $this->timestamp->format( $format );
388 public static function getInstance( $ts =
false ) {
389 return new self( $ts );
Library for creating and parsing MW-style timestamps.
getRelativeTimestamp(MWTimestamp $relativeTo=null, User $user=null, Language $lang=null, array $chosenIntervals=array())
Generate a purely relative timestamp, i.e., represent the time elapsed between the given base timesta...
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
const TS_EXIF
An Exif timestamp (YYYY:MM:DD HH:MM:SS)
const TS_DB
MySQL DATETIME (YYYY-MM-DD HH:MM:SS)
getTimezone()
Get the timezone of this timestamp.
__construct( $timestamp=false)
Make a new timestamp and set it to the specified time, or the current time if unspecified.
const TS_ORACLE
Oracle format time.
format( $format)
Format the timestamp in a given format.
offsetForUser(User $user)
Adjust the timestamp depending on the given user's preferences.
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
static getInstance( $ts=false)
Get a timestamp instance in GMT.
getTimestamp( $style=TS_UNIX)
Get the timestamp represented by this object in a certain form.
when a variable name is used in a it is silently declared as a new masking the global
setTimezone( $timezone)
Set the timezone of this timestamp to the specified timezone.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
const TS_ISO_8601_BASIC
ISO 8601 basic format with no timezone: 19860209T200000Z.
static $formats
Standard gmdate() formats for the different timestamp types.
static getMain()
Static methods.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
setTimestamp( $ts=false)
Set the timestamp to the specified time, or the current time if unspecified.
const TS_POSTGRES
Postgres format time.
diff(MWTimestamp $relativeTo)
Calculate the difference between two MWTimestamp objects.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static getLocalInstance( $ts=false)
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
getHumanTimestamp(MWTimestamp $relativeTo=null, User $user=null, Language $lang=null)
Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
const TS_RFC2822
RFC 2822 format, for E-mail and HTTP headers.
Internationalisation code.
DateTime $timestamp
The actual timestamp being wrapped (DateTime object).