Template:Opmdrts/doc

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
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":

 

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.

Pseudo-code
'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
Implementation notes and scripts to convert existing article text using sed are given in the documentation of the base template Opdrts, see Template:Opdrts.