MediaWiki
1.34.0
|
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. More... | |
Public Attributes | |
const | ALL = -1 |
Used as a preference ID for rules that apply regardless of preference. More... | |
const | DM = 6 |
e.g. More... | |
const | DMY = 2 |
e.g. More... | |
const | ISO = 4 |
e.g. More... | |
const | LAST = 7 |
The highest ID that is a valid target format. More... | |
const | LASTPREF = 4 |
The highest ID that is a valid user preference. More... | |
const | MD = 7 |
e.g. More... | |
const | MDY = 1 |
e.g. More... | |
const | NONE = 0 |
No preference: the date may be left in the same format as the input. More... | |
const | YDM = 5 |
e.g. More... | |
const | YMD = 3 |
e.g. More... | |
Private Member Functions | |
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 from an ISO year, for instance: '400 BC' from '-0399'. More... | |
Private Attributes | |
string[] | $monthNames = [] |
Month names by number. More... | |
int[] | $preferenceIDs |
A map of descriptive preference text to internal format ID. More... | |
string[] | $regexes |
Date format regexes indexed the class constants. More... | |
int[][] | $rules = [] |
Array of special rules. More... | |
string[] | $targetFormats |
Format strings similar to those used by date(), indexed by ID. More... | |
int[] | $xMonths = [] |
Month numbers by lowercase name. More... | |
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 |