MediaWiki REL1_31
DateFormatter Class Reference

Date formatter, recognises dates in plain text and formats them according to user preferences. More...

Collaboration diagram for DateFormatter:

Public Member Functions

 __construct (Language $lang)
 
 reformat ( $preference, $text, $options=[ 'linked'])
 

Static Public Member Functions

static getInstance ( $lang=null)
 Get a DateFormatter object.
 

Public Attributes

const ALL = -1
 
const DM = 7
 
const DMY = 2
 
const ISO1 = 4
 
const ISO2 = 5
 
const LAST = 8
 
const LASTPREF = 4
 
const MD = 8
 
const MDY = 1
 
const NONE = 0
 
const YDM = 6
 
const YMD = 3
 

Private Member Functions

 formatDate ( $bits, $orig, $link=true)
 
 getMonthRegex ()
 Return a regex that can be used to find month names in string.
 
 makeIsoMonth ( $monthName)
 Makes an ISO month, e.g.
 
 makeIsoYear ( $year)
 Make an ISO year from a year name, for instance: '-1199' from '1200 BC'.
 
 makeNormalYear ( $iso)
 Make a year one from an ISO year, for instance: '400 BC' from '-0399'.
 
 replace ( $matches)
 Regexp replacement callback.
 

Private Attributes

string[] $keys
 
 $lang
 
 $mLinked
 
 $monthNames = ''
 
 $mSource
 
 $mTarget
 
 $preferences
 
 $regexes
 
 $rules
 
string[] $targets
 
 $xMonths
 

Detailed Description

Date formatter, recognises dates in plain text and formats them according to user preferences.

Todo:
preferences, OutputPage

Definition at line 29 of file DateFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

DateFormatter::__construct ( Language  $lang)
Parameters
Language$langIn which language to format the date

Definition at line 60 of file DateFormatter.php.

References $lang, ALL, DM, DMY, getMonthRegex(), ISO1, ISO2, MD, MDY, means(), NONE, YDM, and YMD.

Member Function Documentation

◆ formatDate()

DateFormatter::formatDate (   $bits,
  $orig,
  $link = true 
)
private
Parameters
array$bits
string$origOriginal input string, to be returned on formatting failure.
bool$link
Returns
string

Definition at line 241 of file DateFormatter.php.

References $link, $mTarget, makeIsoMonth(), makeIsoYear(), makeNormalYear(), and of.

Referenced by replace().

◆ getInstance()

static DateFormatter::getInstance (   $lang = null)
static

Get a DateFormatter object.

Parameters
Language | null$langIn which language to format the date Defaults to the site content language
Returns
DateFormatter

Definition at line 133 of file DateFormatter.php.

References $cache, $lang, $wgContLang, function, global, use, wfDeprecated(), and wfGetLangObj().

Referenced by CoreParserFunctions\formatDate().

◆ getMonthRegex()

DateFormatter::getMonthRegex ( )
private

Return a regex that can be used to find month names in string.

Returns
string regex to find the months with

Definition at line 340 of file DateFormatter.php.

Referenced by __construct().

◆ makeIsoMonth()

DateFormatter::makeIsoMonth (   $monthName)
private

Makes an ISO month, e.g.

02, from a month name

Parameters
string$monthNameMonth name
Returns
string ISO month name

Definition at line 354 of file DateFormatter.php.

Referenced by formatDate().

◆ makeIsoYear()

DateFormatter::makeIsoYear (   $year)
private

Make an ISO year from a year name, for instance: '-1199' from '1200 BC'.

Parameters
string$yearYear name
Returns
string ISO year name

Definition at line 364 of file DateFormatter.php.

Referenced by formatDate().

◆ makeNormalYear()

DateFormatter::makeNormalYear (   $iso)
private

Make a year one from an ISO year, for instance: '400 BC' from '-0399'.

Parameters
string$isoISO year
Returns
int|string int representing year number in case of AD dates, or string containing year number and 'BC' at the end otherwise.

Definition at line 383 of file DateFormatter.php.

Referenced by formatDate().

◆ reformat()

DateFormatter::reformat (   $preference,
  $text,
  $options = [ 'linked' ] 
)
Parameters
string$preferenceUser preference
string$textText to reformat
array$optionsArray can contain 'linked' and/or 'match-whole'
Returns
string

Definition at line 163 of file DateFormatter.php.

References $options, ALL, LAST, and NONE.

◆ replace()

DateFormatter::replace (   $matches)
private

Regexp replacement callback.

Parameters
array$matches
Returns
string

Definition at line 215 of file DateFormatter.php.

References $matches, $mLinked, $mSource, and formatDate().

Member Data Documentation

◆ $keys

string [] DateFormatter::$keys
private

Definition at line 39 of file DateFormatter.php.

◆ $lang

DateFormatter::$lang
private

Definition at line 36 of file DateFormatter.php.

Referenced by __construct(), and getInstance().

◆ $mLinked

DateFormatter::$mLinked
private

Definition at line 36 of file DateFormatter.php.

Referenced by replace().

◆ $monthNames

DateFormatter::$monthNames = ''
private

Definition at line 31 of file DateFormatter.php.

◆ $mSource

DateFormatter::$mSource
private

Definition at line 30 of file DateFormatter.php.

Referenced by replace().

◆ $mTarget

DateFormatter::$mTarget
private

Definition at line 30 of file DateFormatter.php.

Referenced by formatDate().

◆ $preferences

DateFormatter::$preferences
private

Definition at line 34 of file DateFormatter.php.

◆ $regexes

DateFormatter::$regexes
private

Definition at line 33 of file DateFormatter.php.

◆ $rules

DateFormatter::$rules
private

Definition at line 34 of file DateFormatter.php.

◆ $targets

string [] DateFormatter::$targets
private

Definition at line 42 of file DateFormatter.php.

◆ $xMonths

DateFormatter::$xMonths
private

Definition at line 34 of file DateFormatter.php.

◆ ALL

const DateFormatter::ALL = -1

Definition at line 44 of file DateFormatter.php.

Referenced by __construct(), and reformat().

◆ DM

const DateFormatter::DM = 7

Definition at line 53 of file DateFormatter.php.

Referenced by __construct().

◆ DMY

const DateFormatter::DMY = 2

Definition at line 47 of file DateFormatter.php.

Referenced by __construct().

◆ ISO1

const DateFormatter::ISO1 = 4

Definition at line 49 of file DateFormatter.php.

Referenced by __construct().

◆ ISO2

const DateFormatter::ISO2 = 5

Definition at line 51 of file DateFormatter.php.

Referenced by __construct().

◆ LAST

const DateFormatter::LAST = 8

Definition at line 55 of file DateFormatter.php.

Referenced by reformat().

◆ LASTPREF

const DateFormatter::LASTPREF = 4

Definition at line 50 of file DateFormatter.php.

◆ MD

const DateFormatter::MD = 8

Definition at line 54 of file DateFormatter.php.

Referenced by __construct().

◆ MDY

const DateFormatter::MDY = 1

Definition at line 46 of file DateFormatter.php.

Referenced by __construct().

◆ NONE

const DateFormatter::NONE = 0

Definition at line 45 of file DateFormatter.php.

Referenced by __construct(), and reformat().

◆ YDM

const DateFormatter::YDM = 6

Definition at line 52 of file DateFormatter.php.

Referenced by __construct().

◆ YMD

const DateFormatter::YMD = 3

Definition at line 48 of file DateFormatter.php.

Referenced by __construct().


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