MediaWiki  1.28.0
DateFormatter Class Reference

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

Public Member Functions

 __construct (Language $lang)
 
 formatDate ($bits, $link=true)
 
 getMonthRegex ()
 Return a regex that can be used to find month names in string. More...
 
 makeIsoMonth ($monthName)
 Makes an ISO month, e.g. More...
 
 makeIsoYear ($year)
 Make an ISO year from a year name, for instance: '-1199' from '1200 BC'. More...
 
 makeNormalYear ($iso)
 Make a year one from an ISO year, for instance: '400 BC' from '-0399'. More...
 
 reformat ($preference, $text, $options=[ 'linked'])
 
 replace ($matches)
 

Static Public Member Functions

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

Public Attributes

 $mLinked
 
 $monthNames = ''
 
 $mSource
 
 $mTarget
 
 $pDays
 
 $pMonths
 
 $preferences
 
 $pYears
 
 $regexes
 
 $rules
 
 $rxDM
 
 $rxDMY
 
 $rxMD
 
 $rxMDY
 
 $rxYDM
 
 $rxYMD
 
 $xMonths
 
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
 

Protected Attributes

 $lang
 

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

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

Definition at line 54 of file DateFormatter.php.

References $lang, getMonthRegex(), and means().

Member Function Documentation

DateFormatter::formatDate (   $bits,
  $link = true 
)
Parameters
array$bits
bool$link
Returns
string

Definition at line 228 of file DateFormatter.php.

References $link, $matches, $mTarget, makeIsoMonth(), makeIsoYear(), makeNormalYear(), of, and Html\rawElement().

Referenced by replace().

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

Get a DateFormatter object.

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

Definition at line 127 of file DateFormatter.php.

References $cache, $lang, $wgContLang, ObjectCache\getLocalServerInstance(), global, use, and wfGetLangObj().

Referenced by CoreParserFunctions\formatDate().

DateFormatter::getMonthRegex ( )

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

Returns
string regex to find the months with

Definition at line 326 of file DateFormatter.php.

Referenced by __construct().

DateFormatter::makeIsoMonth (   $monthName)

Makes an ISO month, e.g.

02, from a month name

Parameters
string$monthNameMonth name
Returns
string ISO month name

Definition at line 340 of file DateFormatter.php.

Referenced by formatDate().

DateFormatter::makeIsoYear (   $year)

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 350 of file DateFormatter.php.

Referenced by formatDate().

DateFormatter::makeNormalYear (   $iso)

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 369 of file DateFormatter.php.

Referenced by formatDate().

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 154 of file DateFormatter.php.

References $options.

DateFormatter::replace (   $matches)
Parameters
array$matches
Returns
string

Definition at line 204 of file DateFormatter.php.

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

Member Data Documentation

DateFormatter::$lang
protected

Definition at line 36 of file DateFormatter.php.

Referenced by __construct(), and getInstance().

DateFormatter::$mLinked

Definition at line 36 of file DateFormatter.php.

Referenced by replace().

DateFormatter::$monthNames = ''

Definition at line 31 of file DateFormatter.php.

DateFormatter::$mSource

Definition at line 30 of file DateFormatter.php.

Referenced by replace().

DateFormatter::$mTarget

Definition at line 30 of file DateFormatter.php.

Referenced by formatDate().

DateFormatter::$pDays

Definition at line 33 of file DateFormatter.php.

DateFormatter::$pMonths

Definition at line 33 of file DateFormatter.php.

DateFormatter::$preferences

Definition at line 34 of file DateFormatter.php.

DateFormatter::$pYears

Definition at line 33 of file DateFormatter.php.

DateFormatter::$regexes

Definition at line 33 of file DateFormatter.php.

DateFormatter::$rules

Definition at line 34 of file DateFormatter.php.

DateFormatter::$rxDM

Definition at line 31 of file DateFormatter.php.

DateFormatter::$rxDMY

Definition at line 31 of file DateFormatter.php.

DateFormatter::$rxMD

Definition at line 31 of file DateFormatter.php.

DateFormatter::$rxMDY

Definition at line 31 of file DateFormatter.php.

DateFormatter::$rxYDM

Definition at line 31 of file DateFormatter.php.

DateFormatter::$rxYMD

Definition at line 31 of file DateFormatter.php.

DateFormatter::$xMonths

Definition at line 34 of file DateFormatter.php.

const DateFormatter::ALL = -1

Definition at line 38 of file DateFormatter.php.

const DateFormatter::DM = 7

Definition at line 47 of file DateFormatter.php.

const DateFormatter::DMY = 2

Definition at line 41 of file DateFormatter.php.

const DateFormatter::ISO1 = 4

Definition at line 43 of file DateFormatter.php.

const DateFormatter::ISO2 = 5

Definition at line 45 of file DateFormatter.php.

const DateFormatter::LAST = 8

Definition at line 49 of file DateFormatter.php.

const DateFormatter::LASTPREF = 4

Definition at line 44 of file DateFormatter.php.

const DateFormatter::MD = 8

Definition at line 48 of file DateFormatter.php.

const DateFormatter::MDY = 1

Definition at line 40 of file DateFormatter.php.

const DateFormatter::NONE = 0

Definition at line 39 of file DateFormatter.php.

const DateFormatter::YDM = 6

Definition at line 46 of file DateFormatter.php.

const DateFormatter::YMD = 3

Definition at line 42 of file DateFormatter.php.


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