MediaWiki REL1_34
|
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. | |
Public Attributes | |
const | ALL = -1 |
Used as a preference ID for rules that apply regardless of preference. | |
const | DM = 6 |
e.g. | |
const | DMY = 2 |
e.g. | |
const | ISO = 4 |
e.g. | |
const | LAST = 7 |
The highest ID that is a valid target format. | |
const | LASTPREF = 4 |
The highest ID that is a valid user preference. | |
const | MD = 7 |
e.g. | |
const | MDY = 1 |
e.g. | |
const | NONE = 0 |
No preference: the date may be left in the same format as the input. | |
const | YDM = 5 |
e.g. | |
const | YMD = 3 |
e.g. | |
Private Member Functions | |
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 from an ISO year, for instance: '400 BC' from '-0399'. | |
Private Attributes | |
string[] | $monthNames = [] |
Month names by number. | |
int[] | $preferenceIDs |
A map of descriptive preference text to internal format ID. | |
string[] | $regexes |
Date format regexes indexed the class constants. | |
int[][] | $rules = [] |
Array of special rules. | |
string[] | $targetFormats |
Format strings similar to those used by date(), indexed by ID. | |
int[] | $xMonths = [] |
Month numbers by lowercase name. | |
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 37 of file DateFormatter.php.
DateFormatter::__construct | ( | Language | $lang | ) |
|
static |
Get a DateFormatter object.
Language | null | $lang | In which language to format the date Defaults to the site content language |
Definition at line 169 of file DateFormatter.php.
References $lang.
|
private |
Makes an ISO month, e.g.
02, from a month name
string | $monthName | Month name |
Definition at line 294 of file DateFormatter.php.
Referenced by reformat().
|
private |
Make an ISO year from a year name, for instance: '-1199' from '1200 BC'.
string | $year | Year name |
Definition at line 307 of file DateFormatter.php.
Referenced by reformat().
|
private |
Make a year from an ISO year, for instance: '400 BC' from '-0399'.
string | $iso | ISO year |
Definition at line 325 of file DateFormatter.php.
Referenced by reformat().
DateFormatter::reformat | ( | $preference, | |
$text, | |||
$options = [] ) |
string | $preference | User preference, must be one of "default", "dmy", "mdy", "ymd" or "ISO 8601". |
string | $text | Text to reformat |
array | $options | Ignored. Since 1.33, 'match-whole' is implied, and 'linked' has been removed. |
Definition at line 183 of file DateFormatter.php.
References $source, ALL, LAST, makeIsoMonth(), makeIsoYear(), makeNormalYear(), and NONE.
|
private |
Month names by number.
Definition at line 57 of file DateFormatter.php.
Referenced by __construct().
|
private |
A map of descriptive preference text to internal format ID.
Definition at line 62 of file DateFormatter.php.
|
private |
Date format regexes indexed the class constants.
Definition at line 39 of file DateFormatter.php.
|
private |
Array of special rules.
The first key is the preference ID (one of the class constants), the second key is the detected source format, and the value is the ID of the target format that will be used in that case.
Definition at line 47 of file DateFormatter.php.
|
private |
Format strings similar to those used by date(), indexed by ID.
Definition at line 65 of file DateFormatter.php.
|
private |
Month numbers by lowercase name.
Definition at line 52 of file DateFormatter.php.
const DateFormatter::ALL = -1 |
Used as a preference ID for rules that apply regardless of preference.
Definition at line 68 of file DateFormatter.php.
Referenced by __construct(), and reformat().
const DateFormatter::DM = 6 |
const DateFormatter::DMY = 2 |
const DateFormatter::ISO = 4 |
const DateFormatter::LAST = 7 |
The highest ID that is a valid target format.
Definition at line 98 of file DateFormatter.php.
Referenced by reformat().
const DateFormatter::LASTPREF = 4 |
The highest ID that is a valid user preference.
Definition at line 86 of file DateFormatter.php.
const DateFormatter::MD = 7 |
const DateFormatter::MDY = 1 |
const DateFormatter::NONE = 0 |
No preference: the date may be left in the same format as the input.
Definition at line 71 of file DateFormatter.php.
Referenced by __construct(), and reformat().
const DateFormatter::YDM = 5 |
const DateFormatter::YMD = 3 |