MediaWiki REL1_37
|
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. | |
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. | |
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 | 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. | |
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 166 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 289 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 302 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 320 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 180 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.
|
private |
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().
|
private |
|
private |
|
private |
|
private |
The highest ID that is a valid target format.
Definition at line 95 of file DateFormatter.php.
Referenced by reformat().
|
private |
|
private |
|
private |
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().
|
private |
|
private |