Template:Opmdrts/doc
This is a documentation subpage for Template:Opmdrts. It may contain usage information, categories and other content that is not part of the original template page. |
Opmdrts is short for "Opinion Poll Month-Day Range Table Sorting", following the naming style of {{Date table sorting}} and similar to DMY date style {{Opdrts}} but generating MDY style dates, to show date ranges in opinion poll article tables. A somewhat obscure name was used so better names are left available for any future more general purpose template, and a compact name as it would be heavily used in table rows.
A big advantage of using this template compared to the hand-written expansion is that ndash and hyphen are used correctly, so the sort order works correctly. In converting old hand-written versions to use the template I discovered there were many such errors (often copy-and-pasted forward), plus simple errors like the wrong year in data-sort-value, which were hard/impossible to see in the visual expansion.
Usage
[edit]All parameters are positional, and date elements are a single numeric, or for the month optionally in 3-letter text form eg "Jan" (i.e. not full textual month) as an alternative to "01":
{{opmdrts |Start Day (optional)|End Day|End Month|End Year|"year" (optional formatting instruction)}}
The template displays the range using in a style for North American Opinion polling articles, using 3-letter month name expansion(see examples below), and generates an ISO style data-sort-value from the end date for correct table sorting. The default format is suitable to single year tables, with the "year" format suitable for multi-year tables.
If Start Day is greater than End Day it is taken to be in the previous month; if End Month is January, Dec is used for the displayed start month, but for compactness without its year (one less than End Year) being shown.
Examples
[edit]{{opmdrts|14|15|Oct|2020}}
→ data-sort-value="2020-10-15"|Oct 14–15
{{opmdrts|30|2|10|2020}}
→ data-sort-value="2020-10-02"|Sep 30 – Oct 2
{{opmdrts||24|Aug|2020}}
→ data-sort-value="2020-08-24"|Aug 24
{{opmdrts||12|12|2019|year}}
→ data-sort-value="2019-12-12"|Dec 12, 2019
{{opmdrts|27|2|Jan|2020|year}}
→ data-sort-value="2020-01-02"|Dec 27 – Jan 2, 2020
Pseudo-code
[edit]'data-sort-value="$4-numeric($3)-$2"|' if $1 then if $1 > $2 then 'month($3 - 1) $1 – month($3) $2' else 'month($3) $1–$2' fi else 'month($3) $2' fi if $5 = "year" then ', $4' fi
Implementation notes and scripts to convert existing text
[edit]Implementation notes and scripts to convert existing article text using sed are given in the documentation of the base template {{Opdrts}}, see Template:Opdrts#Implementation notes.
See also
[edit]- {{daterangedash}}: simple date range with full month names and no data-sort-value
- {{Date table sorting}}: more general but for a single date not a range