MediaWiki master
MediaWiki\Parser\DateFormatter Class Reference

Date formatter. More...

Public Member Functions

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

Static Public Member Functions

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

Detailed Description

Date formatter.

Recognises dates and formats them according to a specified preference.

This class was originally introduced to detect and transform dates in free text. It is now only used by the {{#dateformat}} parser function. This is a very rudimentary date formatter; Language::sprintfDate() has many more features and is the correct choice for most new code. The main advantage of this date formatter is that it is able to format incomplete dates with an unspecified year.

Definition at line 41 of file DateFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 129 of file DateFormatter.php.

References MediaWiki\Language\Language\getMonthAbbreviation(), and MediaWiki\Language\Language\getMonthName().

Member Function Documentation

◆ getInstance()

static MediaWiki\Parser\DateFormatter::getInstance ( ?Language $lang = null)
static

Get a DateFormatter object.

Deprecated
since 1.33 use MediaWikiServices::getDateFormatterFactory()
Parameters
Language | null$langIn which language to format the date Defaults to the site content language
Returns
DateFormatter

Definition at line 168 of file DateFormatter.php.

References MediaWiki\MediaWikiServices\getInstance().

◆ reformat()

MediaWiki\Parser\DateFormatter::reformat ( $preference,
$text,
$options = [] )
Parameters
string$preferenceUser preference, must be one of "default", "dmy", "mdy", "ymd" or "ISO 8601".
string$textText to reformat
array$optionsIgnored. Since 1.33, 'match-whole' is implied, and 'linked' has been removed.
Returns
string

Definition at line 182 of file DateFormatter.php.

References $source.


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