Difference between revisions of "Template:Date table sorting/doc"
imported>Mr. Stradivarius (→Error handling: track all errors for now, as we might find unexpected things) |
imported>Mr. Stradivarius (→Dates: add years greater than 9999 and less than -9999) |
||
| Line 19: | Line 19: | ||
| | | | ||
* 1st parameter – Year (optional if month is given) | * 1st parameter – Year (optional if month is given) | ||
| − | ** Positive number (1 to | + | ** Positive number (1 to 999,999,999,999) represent years AD or BC (dependant on the fourth parameter). |
| − | ** Negative numbers (−1 to | + | ** Negative numbers (−1 to −999,999,999,999) represent years BC (without the fourth parameter). |
| + | ** Year numbers must not contain commas or other formatting. | ||
* 2nd parameter – Month (optional if the day is not given either) | * 2nd parameter – Month (optional if the day is not given either) | ||
** Full month name – e.g. February | ** Full month name – e.g. February | ||
| Line 47: | Line 48: | ||
*** Month | *** Month | ||
** Day and month numbers may be 1 or 2 digits, and year numbers may only be 3 or 4 digits. If you need to input a number less than 1000, use leading zeroes (e.g. "0700"). | ** Day and month numbers may be 1 or 2 digits, and year numbers may only be 3 or 4 digits. If you need to input a number less than 1000, use leading zeroes (e.g. "0700"). | ||
| − | ** BC years can only be parsed if the date is only the year number. | + | ** BC years can only be parsed if the date is only the year number. |
| + | ** If you need to include the day or month for BC years or years greater than 9999, you must use separate parameters for year, month and day. | ||
|} | |} | ||
| Line 57: | Line 59: | ||
!hidden sort key | !hidden sort key | ||
!visible output | !visible output | ||
| − | {{dts/testcases/row|span= | + | {{dts/testcases/row|span=3|a={{tlf|dts|''year''}}|1893}} |
{{dts/testcases/row|-89}} | {{dts/testcases/row|-89}} | ||
| + | {{dts/testcases/row|-10000}} | ||
{{dts/testcases/row|a={{tlf|dts|''month''}}|Oct}} | {{dts/testcases/row|a={{tlf|dts|''month''}}|Oct}} | ||
{{dts/testcases/row|a={{tlf|dts|''month year''}}|February 1767}} | {{dts/testcases/row|a={{tlf|dts|''month year''}}|February 1767}} | ||
Revision as of 03:28, 6 July 2015
| This is a documentation subpage for Template:Date table sorting. It contains usage information, categories and other content that is not part of the original template page. |
| This template uses Lua: |
| This template should not be used in citation templates such as Citation Style 1 and Citation Style 2, because it includes markup that will pollute the COinS metadata they produce; see Wikipedia:COinS. |
Dts (date time sorting) is used to correctly sort and display dates in a sortable table (see Help:Sorting).
Contents
What it solves
Normally, for proper sorting, dates must be entered in YYYY-MM-DD format. However, that format does not conform to the Manual of Style for date display. This template automatically creates the hidden key for sorting purposes whilst displaying the date in an alternative format (e.g. day-month-year).
Parameters
Dates
| {{dts|year|month|day|BC}} | {{dts|date}} |
|---|---|
|
|
| input style | input code | hidden sort key | visible output |
|---|---|---|---|
| {{dts|year}} | {{Date table sorting|1893}}
|
1893 | |
{{Date table sorting|-89}}
|
89 BC | ||
{{Date table sorting|-10000}}
|
10,000 BC | ||
| {{dts|month}} | {{Date table sorting|Oct}}
|
Oct | |
| {{dts|month year}} | {{Date table sorting|February 1767}}
|
February 1767 | |
| {{dts|day month year}} | {{Date table sorting|12 Aug 1987}}
|
12 Aug 1987 | |
| {{dts|month day, year}} | {{Date table sorting|July 1, 1867}}
|
July 1, 1867 | |
| {{dts|day month}} | {{Date table sorting|25 October}}
|
25 October | |
| {{dts|month day}} | {{Date table sorting|Jan 1}}
|
Jan 1 | |
| {{dts|YYYY-MM-DD}} | {{Date table sorting|2014-12-09}}
|
December 9, 2014 | |
| {{dts|year|month}} | {{Date table sorting|1990|10}}
|
October 1990 | |
{{Date table sorting|1980|Dec}}
|
Dec 1980 | ||
{{Date table sorting|1970|August}}
|
August 1970 | ||
| {{dts|year|month|day}} | {{Date table sorting|2024|Jun|12}}
|
Jun 12, 2024 | |
{{Date table sorting|-204|11|22}}
|
November 22, 204 BC | ||
| {{dts|year|month|day|era}} | {{Date table sorting|44|3|15|BC}}
|
March 15, 44 BC | |
{{Date table sorting|94|Oct|17|AD}}
|
Oct 17, 94 | ||
| {{dts||month}} | {{Date table sorting||May}}
|
May | |
| {{dts||month|day}} | {{Date table sorting||Sep|12}}
|
Sep 12 |
Formatting
Using format produces a format that depends on, but is not necessarily equal to the format of the supplied date. The format parameter can take nine values.
| value | function | input code | hidden sort key | visible output |
|---|---|---|---|---|
| format depends on the input | {{Date table sorting|26 Jan 1788}}
|
26 Jan 1788 | ||
{{Date table sorting|March 12, 1557}}
|
March 12, 1557 | |||
{{Date table sorting|1975-02-13}}
|
February 13, 1975 | |||
dmy |
displays the date in day-month-year format | {{Date table sorting|Sep 13, 1888|format=dmy}}
|
13 Sep 1888 | |
{{Date table sorting|1983-01-03|format=dmy}}
|
3 January 1983 | |||
dm |
displays only the day and month in day-month format | {{Date table sorting|Feb 26, 1788|format=dm}}
|
26 Feb | |
{{Date table sorting|2020-10-15|format=dm}}
|
15 October | |||
mdy |
displays the date in month-day-year format | {{Date table sorting|August 31, 1901|format=mdy}}
|
August 31, 1901 | |
{{Date table sorting|2006-11-08|format=mdy}}
|
November 8, 2006 | |||
md |
displays only the day and month in month-day format | {{Date table sorting|26 Jun 1988|format=md}}
|
Jun 26 | |
{{Date table sorting|2002-05-27|format=md}}
|
May 27 | |||
my |
displays only the month and year in month-year format | {{Date table sorting|16 November 1488|format=my}}
|
November 1488 | |
d |
displays only the day | {{Date table sorting|6 July 1666|format=d}}
|
6 | |
m |
displays only the month | {{Date table sorting|1980-02-12|format=m}}
|
February | |
y |
displays only the year | {{Date table sorting|-26|Jan|18|format=y}}
|
26 BC | |
hide |
hides the date | {{Date table sorting|15 October 1800|format=hide}}
|
Abbreviation
There are two ways of abbreviating the month name.
- Directly input an abbreviated month name.
- Use the
abbr=onparameter.
| abbreviation method | input code | hidden sort key | visible output |
|---|---|---|---|
| none | {{Date table sorting|2000-01-01}}
|
January 1, 2000 | |
{{Date table sorting|2000|1|1}}
|
January 1, 2000 | ||
{{Date table sorting|1 January 2000}}
|
1 January 2000 | ||
{{Date table sorting|2000|January|1}}
|
January 1, 2000 | ||
| abbreviated input | {{Date table sorting|1 Jan 2000}}
|
1 Jan 2000 | |
{{Date table sorting|2000|Jan|1}}
|
Jan 1, 2000 | ||
abbr=on |
{{Date table sorting|1 January 2000|abbr=on}}
|
1 Jan 2000 | |
{{Date table sorting|2000|January|1|abbr=on}}
|
Jan 1, 2000 | ||
{{Date table sorting|2000-01-01|abbr=on}}
|
Jan 1, 2000 | ||
{{Date table sorting|2000|1|1|abbr=on}}
|
Jan 1, 2000 |
Additional sort key
In case two dates in a table are identical they may be ordered using the addkey parameter.
| input code | hidden sort key | visible output |
|---|---|---|
{{Date table sorting|2010-10-10|addkey=3}}
|
October 10, 2010 | |
{{Date table sorting|2010-10-09}}
|
October 9, 2010 | |
{{Date table sorting|2010-10-10|addkey=1}}
|
October 10, 2010 | |
{{Date table sorting|2010-10-10}}
|
October 10, 2010 | |
{{Date table sorting|2010-10-10|addkey=4}}
|
October 10, 2010 | |
{{Date table sorting|2010-10-11}}
|
October 11, 2010 | |
{{Date table sorting|2010-10-10|addkey=2}}
|
October 10, 2010 |
Wrapping
To turn off the suppression of word wraps, use the nowrap=off parameter.
Notes
Sorting for incomplete dates
- Whole months or years
- A whole year or month (and year) is sorted according to its first day.
- Missing years
- If the year is not specified, the date will be sorted as if the year were the current year.
- Blank dates
- For no date input at all, the maximum possible sort key is used, so the entry will sort last.
Error handling
Entering an invalid date format will (generally) produce an error message such as the one below.
Error in Template:Date table sorting: days must be an integer between 1 and 31
Errors are put in Category:Dts templates with errors.
Calendar choice
The template is not capable of distinguishing Julian and Gregorian calendar dates. Also, it is not capable of taking a date in one calendar as input and outputting a date in the other calendar. Thus, to insure proper sorting, editors must either use one calendar for all dates, or pick a specific changeover date (for example, deciding that 4 October 1582 is Julian and all later dates are Gregorian); this would be done on an article-by article basis. Editors are also responsible for explaining to the reader whether the visible dates are Julian or Gregorian, if there is any possibility of confusion.
Linking
The template formerly linked dates automatically, with link=off used to suppress linking. In accordance with current guidelines linking of dates is no longer supported and instances of link=off should be removed.
See also
- m:Template:dts (backlinks edit), since on Meta e.g. 09999 9999 induces numeric sort mode, "&" is prefixed to force string sort mode.
- {{sort}}, sorting by a specified key (also good for complicated numbers, e.g. scientific notation)
- {{sortname}}, full name sorting (using "last name, first name" as default sort key)
- {{tts}}, for sorting times in result tables of athletic events (only needed in certain cases - see template documentation)
- {{mss}}, for sorting times in tables of eclipses
- {{nts}}, for numbers