Module:Auto date formatter/doc
![]() | This is a documentation subpage for Module:Auto date formatter. It may contain usage information, categories and other content that is not part of the original module page. |
![]() | This module depends on the following other modules: |
This module allows non-cs1|2 templates and templates that do not wrap cs1|2 templates to have automatic date formatting according to an article's {{use dmy dates}}
or {{use mdy dates}}
template. This module obeys date style (long, abbreviated, year initial) specified by the |cs1-dates=
parameter. See Template:Use dmy dates § Auto-formatting citation template dates for additional information about |cs1-dates=
.
Usage
[edit]This module should be invoked from within other citation templates.
For publication dates:
{{#invoke:auto date formatter|pub_date_format|<date>}}
For access and archive dates:
{{#invoke:auto date formatter|access_archive_format|<date>}}
If {{use dmy dates}}
or {{use mdy dates}}
are present in an article, the above functions return <date>
in the format specified by the {{use xxx dates}}
template in the style specified by |cs1-dates=
if present. This module uses Module:Citation/CS1/Configuration to determine the format and style to apply to dates.
When the article does not have a {{use xxx dates}}
template, this module returns <date>
as is. If it cannot parse the date, the module will output the date as written. It does not offer warnings or maintenance categories for malformed or unusual dates.
The table below shows how the module would modify several dates on a page with {{use dmy dates|cs1-dates=ly}}
:
Date as written | pub_date_format | access_archive_format |
---|---|---|
31 October 1990 | 31 October 1990 | 1990-10-31 |
October 31, 1990 | 31 October 1990 | 1990-10-31 |
31-10-1990 | 31 October 1990 | 1990-10-31 |
Oct. 31st, 1990 | 31 October 1990 | 1990-10-31 |
31 de octubre de 1990 | 31 de octubre de 1990 | 31 de octubre de 1990 |
Halloween 1990 | Halloween 1990 | Halloween 1990 |
Adding to a template
[edit]Most citation templates on Wikipedia are CS1 or CS2 templates, and they auto-format dates. You can make new citation templates as specific-source templates. Built on existing CS1 templates, they also auto-format dates. This results in consistency with the most used citation templates and reduces the maintenance burden on the specific-source template. For example, {{cite sports-reference}} is based on the widely used {{cite web}} template.
Source types that do not easily map to a CS1 template may have citation templates written from scratch. In these cases, this module can provide similar auto-formatting for dates. For example, {{cite comic}} was not converted to CS1 because of the way it handles authors. When a template is written in wikitext, you can wrap the parameter reference inside an invocation of this module:
Wikitext | Replacement |
---|---|
{{{date}}}
|
{{#invoke:Auto date formatter|pub_date_format|{{{date}}}}}
|
{{{access-date}}}
|
{{#invoke:Auto date formatter|access_archive_format|{{{access-date}}}}}
|
Lua modules for non-CS1 templates can access this template from the functions _pub_date_format()
and _access_archive_format()
.