[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/ -> MWTimestamp.php (summary)

Creation and parsing of MW-style timestamps. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Author: Tyler Romeo, 2012
File Size: 422 lines (12 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class

MWTimestamp:: (13 methods):
  __construct()
  setTimestamp()
  getTimestamp()
  getHumanTimestamp()
  offsetForUser()
  getRelativeTimestamp()
  __toString()
  diff()
  setTimezone()
  getTimezone()
  format()
  getLocalInstance()
  getInstance()


Class: MWTimestamp  - X-Ref

Library for creating and parsing MW-style timestamps. Based on the JS
library that does the same thing.

__construct( $timestamp = false )   X-Ref
Make a new timestamp and set it to the specified time,
or the current time if unspecified.

param: bool|string $timestamp Timestamp to set, or false for current time

setTimestamp( $ts = false )   X-Ref
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.

param: string|bool $ts Timestamp to store, or false for now

getTimestamp( $style = TS_UNIX )   X-Ref
Get the timestamp represented by this object in a certain form.

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

param: int $style Constant Output format for timestamp
return: string The formatted timestamp

getHumanTimestamp( MWTimestamp $relativeTo = null,User $user = null, Language $lang = null)   X-Ref
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.

param: MWTimestamp|null $relativeTo The base timestamp to compare to
param: User|null $user User the timestamp is being generated for (or null
param: Language|null $lang Language to use to make the human timestamp
return: string Formatted timestamp

offsetForUser( User $user )   X-Ref
Adjust the timestamp depending on the given user's preferences.

param: User $user User to take preferences from
return: DateInterval Offset that was applied to the timestamp

getRelativeTimestamp(MWTimestamp $relativeTo = null,User $user = null,Language $lang = null,array $chosenIntervals = array()   X-Ref
Generate a purely relative timestamp, i.e., represent the time elapsed between
the given base timestamp and this object.

param: MWTimestamp $relativeTo Relative base timestamp (defaults to now)
param: User $user Use to use offset for
param: Language $lang Language to use
param: array $chosenIntervals Intervals to use to represent it
return: string Relative timestamp

__toString()   X-Ref

return: string

diff( MWTimestamp $relativeTo )   X-Ref
Calculate the difference between two MWTimestamp objects.

param: MWTimestamp $relativeTo Base time to calculate difference from
return: DateInterval|bool The DateInterval object representing the

setTimezone( $timezone )   X-Ref
Set the timezone of this timestamp to the specified timezone.

param: string $timezone Timezone to set

getTimezone()   X-Ref
Get the timezone of this timestamp.

return: DateTimeZone The timezone

format( $format )   X-Ref
Format the timestamp in a given format.

param: string $format Pattern to format in
return: string The formatted timestamp

getLocalInstance( $ts = false )   X-Ref
Get a timestamp instance in the server local timezone ($wgLocaltimezone)

param: bool|string $ts Timestamp to set, or false for current time
return: MWTimestamp The local instance

getInstance( $ts = false )   X-Ref
Get a timestamp instance in GMT

param: bool|string $ts Timestamp to set, or false for current time
return: MWTimestamp The instance



Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1