Misplaced Pages

User:Ohconfucius/script/MOSNUM dates: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:Ohconfucius | script Browse history interactively← Previous editContent deleted Content addedVisualWikitext
Revision as of 21:20, 15 January 2016 editWikiWikiWayne (talk | contribs)Extended confirmed users37,087 editsm Known limitations: italics and namestyle← Previous edit Latest revision as of 10:06, 16 August 2024 edit undoMichael Bednarek (talk | contribs)Autopatrolled, Extended confirmed users84,942 editsm Undid revision 1240591949 by Kennethmacalpine (talk): restore installation instructions.Tag: Undo 
(57 intermediate revisions by 12 users not shown)
Line 1: Line 1:

{{Message {{Message
| bgcolor = lightblue | bgcolor = lightblue
Line 7: Line 6:
| message = bug report or suggestion | message = bug report or suggestion
| link = Misplaced Pages:Date formattings/script/MOSNUM dates/bugs | link = Misplaced Pages:Date formattings/script/MOSNUM dates/bugs
| extra-style = extra styles, like border-radius etc... | extra-style = extra styles, like border-radius, etc...
| width = | width =
| margin = 10px | margin = 10px
| padding = 20px | padding = 20px
| text-align = left | text-align = left
}}
}}{{shortcut|WP:Mosnumscript|WP:MOSNUMscript}}
]


{{shortcut|WP:Mosnumscript|WP:MOSNUMscript}}
==Overview==
]
This script delinks all dates and date fragments, and converts them all to the same format, either dd mmm yyyy ("14 July 1978") or mmm dd, yyyy ("July 14, 1978").


== Overview ==
MOSNUM allows one other format to be used in articles &ndash; but only in tables and reference sections. Although the yyyy-mm-dd dates ("1978-07-14") used in Misplaced Pages are '''not actually fully ]-compliant''', they are shorthanded in the sidebar button to "ISO" due to space constraints.
This script delinks all dates and date fragments and converts them all to the same format, either dd mmm yyyy ("14 July 1978") or mmm dd, yyyy ("July 14, 1978").


MOSNUM allows one other format to be used in articles &ndash; but only in tables and reference sections.
'''''NOTE:''' Functions converting dates within citation templates has been withdrawn now that ] software engine renders date formats automatically''
There are modes that allow the user to select whether to treat body dates only or body and reference sections: There are modes that allow the user to select whether to treat body dates only or body and reference sections:
#'''all dates to dmy''' &ndash; dates in the body of the text as well as in the reference sections are converted to "14 July 1978" or similar. # '''all dates to dmy''' &ndash; dates in the body of the text as well as in the reference sections are converted to "14 July 1978" or similar.
#'''all dates to mdy''' &ndash; as above. dates are converted to "July 14, 1978" or similar. # '''all dates to mdy''' &ndash; as above. dates are converted to "July 14, 1978" or similar.
# '''<s>Big endian ref dates</s>''' button now disabled. Users are invited to manually add {{para|cs1-dates}} parameter to {{tl|Use dmy dates}} or {{tl|Use mdy dates}} causing applicable dates to be rendered in ''{{date|{{date}}|iso}}'' YMD format
#'''body dates to dmy''' &ndash; no yyyy-mm-dd dates ("1978-07-14") converted
#'''body dates to mdy''' &ndash; no yyyy-mm-dd dates ("1978-07-14") converted
<!-- Commented out modes that have been removed
#'''ISO to dmy''' &ndash; only ''ISO-style'' dates within ref tags are converted
#'''ISO to mdy''' &ndash; only ''ISO-style'' dates within ref tags are converted -->
In addition, there are the following six modes to convert slash or contracted dates into the desired format:


In addition, there are the following modes to convert slash or contracted dates into the desired format:
#'''Del year-in-X dates''' &ndash; unlinks the most common 'year-in-X' links
<!--
#'''US-slash dates''' &ndash; resolves US style slash-dates (e.g. 7/27/1961, 07/27/1961, 07/27/61, 7/27/61), or dates using the full stop or hyphens as separator (e.g. 7.27.1961, 7.27.1961, 7.27.61, 7.27.61, 7-27-1961, 7-27-1961, 7-27-61, 7-27-61), into mdy format
# '''Expand ref dates''' &ndash; Expand month names within the references section
#'''UK-slash dates''' &ndash; resolves UK/European style slash-dates (e.g. 27/7/1961, 27/07/1961, 27/07/61, 27/7/61), or dates using the full stop or hyphens as separator (e.g. 27.7.1961, 27.07.1961, 27.07.61, 27.7.61, 27-7-1961, 27-07-1961, 27-07-61, 27-7-61), into dmy format
#'''Expand ref dates''' &ndash; Expand month names within the references section # '''Expand all dates''' &ndash; Expand month names elsewhere within the article
-->#'''US-slash dates''' &ndash; converts dates that use slash or decimal separators in formats commonly used in the US into '''mdy''' dates ''viz'': <code>mm/dd/yy</code>, <code>mm/dd/yyyy</code>, <code>mm.dd.yy</code> or <code>mm.dd.yyyy</code>
#'''Expand all dates''' &ndash; Expand month names elsewhere within the article
# '''UK-slash dates''' &ndash; converts dates that use slash or decimal separators in formats commonly used in the UK, Europe and elsewhere into '''dmy''' dates ''viz'': <code>dd/mm/yy</code>, <code>dd/mm/yyyy</code>, <code>dd.mm.yy</code> or <code>dd.mm.yyyy</code>
#'''Abbrev ref dates''' &ndash; Abbreviate month names within the references section
''* '''Note''': In these latter 2 cases, false positives are more likely because the protection mechanism of the script is bypassed, meaning the regex will act on dates in instances other than where the {{para|date}} parameter is used''


== History == == History ==
Lightmouse initially created a script to deal with a number of general formatting issues, and date alignment was one such function. I used it and often gave feedback and bug reports. Seeing the need to work on the diversity of date formats and date situations that are seen here on Misplaced Pages, I created an independent script targeted at dates with some help and advice from Lightmouse. Lightmouse initially created a script to deal with a number of general formatting issues, and date alignment was one such function. I used it and often gave feedback and bug reports. Seeing the need to work on the diversity of date formats and date situations that are seen here on Misplaced Pages, I created an independent script targeted at dates with some help and advice from Lightmouse.


Over the years, this script has been built on and refined. But it was getting unwieldy, and was getting slow, and harder and harder to maintain. Over the years, this script has been built on and refined. In April 2012, the engine underwent a major rework by {{User|1exec1}}, who built it and incorporated a new regex_worker function that allows more effective treatment of date fragments; there is better protection of strings that ought not to be modified by the script. In May, the new improved version of the script went 'live'.


== Detailed functional overview ==
In April 2012, the engine underwent a major rework by {{User|1exec1}}, who built it and incorporated a new regex_worker function that allows more effective treatment of date fragments; there is better protection of strings that ought not to be modified by the script. In May, the new improved version of the script went 'live'.
The dates script is at ''']'''.
* It is aimed to make displayed dates fully compatible with ] (WP:MOSNUM)
* It ensures uniform presentation of dates within any given article. As such, it:
** delinks all dates and date fragments, including day-month strings, days, months, decades, centuries,
** converts all these date fragments to the same format, either dd mmm yyyy or mmm dd, yyyy, at the option of the user
** removes ordinal suffixes and constructions such as '<span style="color:orange;">the</span> 5<span style="color:orange;">th of</span> September', 'December 25<span style="color:orange;">th</span>' or 'October <span style="color:orange;">of</span> 2003'
** adds commas where necessary (e.g. February 28, 2001)
** removes redundant commas (e.g. July<span style="color:orange;">,</span> 1997; 28 February<span style="color:orange;">,</span> 2001)
* It removes direct links to dates and most forms of piped date links
* It removes <s>year linking templates (such as {{tl|scy}}, {{tl|by}}), and</s> links to 'year-in X' where piped from years (such as <nowiki>]</nowiki>)
* It converts other often used (but not MOSNUM-compliant) date formats within the references section, such as dd-mm-yyyy or dd-mmm-yyyy to the chosen prevailing format used in the rest of the article.
* It makes certain fixes that may be identified as ]
* <s>It also allows users to choose to convert dates within only the body of the article, as is permitted for reference sections (where yyyy-mm-dd dates are common) to have different dates, or throughout the article.</s> Now disabled. CS1 now manages the date rendering by ] using parameters within the {{tl|use dmy dates}} and {{tl|use mdy dates}} templates, so this can be used to fine-tune the rendering.


<!-- * ISO-style dates (yyyy-mm-dd) which are outside <nowiki><ref></ref></nowiki> tags are not acted upon by the script -->
==Overview==
The dates script is at ''']'''.
*It is aimed to make displayed dates fully compatible with ] (WP:MOSNUM)
*It ensures uniform presentation of dates within any given article. As such, it:
**delinks all dates and date fragments, including day-month strings, days, months, decades, centuries,
**converts all these date fragments to the same format, either dd mmm yyyy or mmm dd, yyyy, at the option of the user
**removes ordinal suffixes and constructions such as '<font color=orange>the</font> 5<font color=orange>th of</font> September', 'December 25<font color=orange>th</font>' or 'October <font color=orange>of</font> 2003'
**adds commas where necessary (e.g. February 28 2001)
**removes redundant commas (e.g. July<font color=orange>,</font> 1997; 28 February<font color=orange>,</font> 2001)
*It removes direct links to dates, and most form of piped date links
*It removes year linking templates (such as {{tl|scy}}, {{tl|by}}), and links to 'year-in X' where piped from years (such as <nowiki>]</nowiki>)
*It converts other often used (but not MOSNUM-compliant) date formats within the references section, such as dd-mm-yyyy or dd-mmm-yyyy to the chosen prevailing format used in the rest of the article.
*It also allows users to choose to convert dates within only the body of the article, as is permitted for reference sections (where yyyy-mm-dd dates are common) to have different dates, or throughout the article.
*ISO-style dates (yyyy-mm-dd) which are outside <nowiki><ref></ref></nowiki> tags are not acted upon by the script


The script adds or updates a non-displaying template {{tl|use mdy dates}} or {{tl|use dmy dates}} depending on the conversion used. This tagging allows for easy future maintenance for anybody armed with ]. The script adds or updates a non-displaying template {{tl|use mdy dates}} or {{tl|use dmy dates}} depending on the conversion used. This tagging allows for WM software engine to render date formats automatically in conformity with tagged format). It also facilitates future maintenance by bot by script ].


The script will achieve overall consistency of the '''format''' of the date, but will ''not'' alter the '''form''' (i.e. month spelt out in full or abbreviated to 3 or 4 letters. This task is assured by 'Expand ref dates', 'Expand all dates' and 'Abbrev ref dates' functions. The script will achieve overall consistency of the '''format''' of the date<!-- , but will ''not'' alter the '''form''' (i.e. month spelt out in full or abbreviated to 3 or 4 letters. This task is assured by 'Expand ref dates', 'Expand all dates' and 'Abbrev ref dates' functions -->. The format and syntax of citations were modelled after the way reference sections are rendered when using the most common citation templates – {{tl|cite news}} and {{tl|cite web}}; I try to stick to syntax in <nowiki>{{cite web}}</nowiki> where 'Retrieved' is capitalised and preceded by a full-stop.


Although the MediaWiki software interprets {{tl|use dmy dates}} or {{tl|use mdy dates}} templates, allowing dates and access dates within citation templates to be automatically formatted, errors there and elsewhere may still require correction. The script takes care of that.
The format and syntax of citations were modelled after the way reference sections are rendered when using the most common citation templates – {{tl|cite news}} and {{tl|cite web}}; I try to stick to syntax in <nowiki>{{cite web}}</nowiki> where 'Retrieved' is capitalised and preceded by a full-stop.


=== How it works === === How it works ===
The script is configured so that dates are stored as an array. The given ] and substitution strings can contain ]s that specify what date format the routine should accept and to what date format the routine should convert the date to. The script is configured so that dates are stored as an array. The given ] and substitution strings can contain ]s that specify what date format the routine should accept and to what date format the routine should convert the date to.


There is a mechanism in place to protect a wide range of strings that ought to be immutable: such as images, categories, urls; text within blockquotes and double quotes; text within certain parameters (e.g. <code>|title=</code>). There is a mechanism in place to protect a wide range of strings that ought to be immutable: such as images, categories, urls; text within blockquotes and double quotes; text within certain parameters (e.g. <code>|title=</code>). Occasionally, due to the proliferation of templates across en.wp, some may be the subject of unintended changes that have not been anticipated in the script regexes.

As also mentioned ], the actions of the protection mechanism can be revealed in the event of the script stalling, and substitution markers may appear in the edit window. When this occurs, the user should abandon the action, reopen the edit window and reperform the edit.

=== Optional auto-formatting citation template dates ===
Script default is without parameter, in which case date is aligned to the prevailing style, dmy or mdy.

] and ] (collectively cs1|2) templates automatically render dates ({{para|date}}, {{para|access-date}}, {{para|archive-date}}, etc) in the style specified by this template. Because it is allowed by ], the cs1|2 templates can automatically format dates in a variety of styles. Editors may choose how cs1|2 templates render dates by the use of {{para|cs1-dates|&lt;{{var|keyword}}>}}.
{{#lst:Help:Citation Style 1|auto_date_format_table}}

An example is given at {{section link|Help:Citation Style 1#Auto-formatting citation template dates}}.


=== Credits === === Credits ===
Line 77: Line 85:
{{User:Ohconfucius/script/install}} {{User:Ohconfucius/script/install}}


==Actions and test== == Actions and test ==
'''Use of the ] or '']'' browsers is highly recommended'''. '''Use of the ] or '']'' browsers is highly recommended'''. It only functions in desktop mode.


The script is continually being run, and seems to work as intended on the latest Firefox and Chrome browsers on Mac and Windoze. On Windows machines, browser-specific issues for IE, specifically ], are . The script is continually being run and seems to work as intended on the latest Firefox and Chrome browsers on Mac and Windows. On Windows machines, browser-specific issues for IE, specifically ] . These may or may not have been resolved.

The tool may also be used on mobile browsers. However, extensive testing has not been undertaken.


Once you are in edit mode, there are buttons in the toolbox in the left margin: Once you are in edit mode, there are buttons in the toolbox in the left margin:
#all dates to dmy #'''DATES to dmy'''{{snd}}converts all dates to ''{{date|{{date}}|dmy}}'' dmy format
#all dates to mdy #'''DATES to mdy'''{{snd}}converts all dates to ''{{date|{{date}}|mdy}}'' mdy format
#'''US-slash dates''' &ndash; converts all applicable dates into ''{{date|{{date}}|mdy}}'' mdy format
#body dates to dmy (''ISO-style dates within ref tags are avoided'')
#'''UK-slash dates''' &ndash; converts all applicable dates into ''{{date|{{date}}|dmy}}'' dmy format
#body dates to mdy

#Del year-in-X dates
;Notes
#Expand all dates (''month names within the article'')
{{Notelist}}
#Abbrev ref dates (''only month names within the references section'')
#Accessdate to YYYY-MM-DD (''only access dates within the references section'')
#US-slash dates
#UK-slash dates


<span class="plainlinks">Users are equally reminded of the following provisions of </span>: <span class="plainlinks">Users are equally reminded of the following provisions of </span>:
<blockquote> <blockquote>


=====Format consistency===== ===== Format consistency =====
* Dates in article body text should all use the same format: Julia ate a poisoned apple on 25 June 2005, and died on 28 June (not ... on June 28). * Dates in article body text should all use the same format: Julia ate a poisoned apple on 25 June 2005, and died on 28 June (not ... on June 28).
* Publication dates in references should all use the same format. Any format from the "Acceptable date formats" table above may be used, unless the citation style being used requires a different format (however, all-numeric date formats other than yyyy-mm-dd must still be avoided). * Publication dates in references should all use the same format. Any format from the "Acceptable date formats" table above may be used unless the citation style being used requires a different format (however, all-numeric date formats other than yyyy-mm-dd must still be avoided).
* Access and archive dates in references should all use the same format – either the format used for publication dates, or yyyy-mm-dd * Access and archive dates in references should all use the same format – either the format used for publication dates or yyyy-mm-dd


(These consistency requirements apply to dates in general prose and reference citations, but not to dates in quotations or titles) (These consistency requirements apply to dates in general prose and reference citations, but not to dates in quotations or titles)


=====Strong national ties to a topic===== ===== Strong national ties to a topic =====
{{shortcut|WP:STRONGNAT|WP:TIES}} {{shortcut|WP:STRONGNAT|WP:TIES}}

* Articles on topics with strong ties to a particular English-speaking country should generally use the more common date format for that nation. For the United States, this is month before day; for most others, it is day before month. Articles related to Canada may use either format consistently. * Articles on topics with strong ties to a particular English-speaking country should generally use the more common date format for that nation. For the United States, this is month before day; for most others, it is day before month. Articles related to Canada may use either format consistently.
* Sometimes the customary format differs from the usual national one: for example, articles on the modern US military use day before month, in accordance with military usage. * Sometimes the customary format differs from the usual national one: for example, articles on the modern US military use day before month, in accordance with military usage.


=====Retaining the existing format===== ===== Retaining the existing format =====
{{shortcut|WP:RETAIN}} {{shortcut|WP:RETAIN}}

* If an article has evolved using predominantly one format, the whole article should conform to it, unless there are reasons for changing it based on strong national ties to the topic or consensus on article talk. * If an article has evolved using predominantly one format, the whole article should conform to it, unless there are reasons for changing it based on strong national ties to the topic or consensus on article talk.
* The date format chosen by the first major contributor in the early stages of an article should continue to be used, unless there is reason to change it based on strong national ties to the topic or consensus on article talk. * The date format chosen by the first major contributor in the early stages of an article should continue to be used, unless there is reason to change it based on strong national ties to the topic or consensus on article talk.
Line 117: Line 126:


==== Test pages ==== ==== Test pages ====
*] - tests unlinking and dmy<&ndash;>mdy conversion * ] - tests unlinking and dmy<&ndash;>mdy conversion
*] - slash dates * ] - slash dates
* ] – test page dealing with ]

===Known limitations===


=== Known limitations ===
* '''Proper nouns with dates''': A number of proper nouns containing date fragments (such as ']', ']', ']', ']') have been specifically protected from conversion or delinking. Only the displayed part of piped links are acted upon, whilst the underlying pipe will not be changed. For the purposes of this script, ] or ] ''is'' treated: there are ample redirects in existence for any problems to be mitigated. '''Let me know if there are other proper names which ought to be protected'''. * '''Proper nouns with dates''': A number of proper nouns containing date fragments (such as ']', ']', ']', ']') have been specifically protected from conversion or delinking. Only the displayed part of piped links are acted upon, whilst the underlying pipe will not be changed. For the purposes of this script, ] or ] ''is'' treated: there are ample redirects in existence for any problems to be mitigated. '''Let me know if there are other proper names which ought to be protected'''.
* '''Dates that are used as adjectives''': Because the script routinely removes the leading "the" for dates, attention should be paid to where the date is used as an adjective, such as "<font color=orange>the</font> 6 June beach landings". The "the" should either be reinserted, or the phrase reconfigured so that the date is no longer adjectival (e.g. "the beach landings on 6 June"). * '''Dates that are used as adjectives''': Because the script routinely removes the leading "the" for dates, attention should be paid to where the date is used as an adjective, such as "<span style="color:orange;">the</span> 6 June beach landings". The "the" should either be reinserted, or the phrase reconfigured so that the date is no longer adjectival (e.g. "the beach landings on 6 June").
<!-- * '''"body dates" functions''': When these two functions are run, the script protects all within <nowiki><ref></ref></nowiki> tags, so that no dates within citations will be changed, '''even if they are incorrect''' (ie mdy in dmy articles and vice versa). As a consequence, there are corrections the full script makes dates such as missing commas (eg Sept 27 2013), extra commas (eg 27 Sept, 2013) or misspelt month names or missing capitalisation (eg 2 mars 2013), which will not happen with these functions. ''For the above reason, the function – which has been disabled once and restated due to a specific request – may be withdrawn permanently in due course.'' -->
* '''Non-ISO-style date within citation''': The 'body dates' functions will act on any non-ISO-style date within citation, so that if there is a dmy date within references (amongst dates such as 2009-01-11), the former will be acted on by the mdy function whilst the latter will be unaffected.
* '''Stalling''': If you see characters such as the following in your diffs window, don't panic:
* '''wikEd''': There is a conflict with '']'' that prevents the ''MOSNUM dates'' script from making ''any'' changes to articles. The solution is to toggle the ''wikEd'' text area ''off'' while running'' MOSNUM dates''. ''wikEd'' has an easy toggle button for that called: ''Use wikEd instead of classic text area''. Simply press the toggle button so the button pops out (off), then run ''MOSNUM dates''. When you are done running ''MOSNUM dates'' you can press the toggle button again so the toggle button pops in (on) and the ''wikEd text area'' will be live again. Once you get in the habit of toggling the ''wikEd text area'' ''on'' and ''off'', running ''MOSNUM dates'' is no longer a conflict with ''wikEd''. There is no need to disable/re-enable wikEd in your common.js file.
::<code>⍌190⍍</code>
::<code>⍌191⍍</code>
:this is simply the result of a stalling of the script, where the protected strings haven't been restored by the time you see the changes displayed on screen. It happens occasionally. In such a case, you should abandon the edit by refreshing the edit window, and then click on the script button again.

=== Known conflicts ===
==== Other Wiki scripts or gadgets ====
* '''wikEd''': The script is known to conflict with '']'' that prevents the ''MOSNUM dates'' script from making ''any'' changes to articles, or simply blocking the creation of a script button. The solution is to toggle the ''wikEd text area'' '''''off''''' while running'' MOSNUM dates''. ''wikEd'' has an easy toggle button for that called: ''Use wikEd instead of classic text area''. Simply press the toggle button so the button pops out (off), then run ''MOSNUM dates''. When you are done running ''MOSNUM dates'' you can press the toggle button again so the toggle button pops in (on) and the ''wikEd text area'' will be live again. Once you get in the habit of toggling the ''wikEd text area'' '''''on''''' and '''''off''''', running ''MOSNUM dates'' is no longer a conflict with ''wikEd''. There is no need to disable/re-enable wikEd in your common.js file.

==== Browsers ====
* It has that Chrome extension "]" may somehow inhibit the script functioning.


== Disclaimers == == Disclaimers ==
I use and make experimental changes to another version, and update this production version regularly to a suitably stable prior version of the test script. However, like all software, bugs are unavoidable. Use at your own risk, and make sure you '''check the edit changes before you save'''. The script is continually being run, and seems to work as intended on the latest Firefox and Chrome browsers. However, browser-specific issues have been for IE on Windows machines. I use and make experimental changes to another version, and update this production version regularly to a suitably stable prior version of the test script. However, like all software, bugs are unavoidable. Use at your own risk, and make sure you '''check the edit changes before you save'''. The script is continually being run and seems to work as intended on the latest Firefox and Chrome browsers. However, browser-specific issues have been for IE on Windows machines in the past (as at 1 January 2019, there are no recent reports of such compatibility issues).


By consensus, this script should not be used in articles about chronological periods, such as ], as date links here, considered desirable, would otherwise be automatically removed. Equally, I suspect that using the script on talk pages or on WP pages is likely to result in more angst than benefit to the project. By consensus, this script should not be used in articles about chronological periods, such as ] or ], as date links here, considered desirable, would otherwise be automatically removed. Equally, I suspect that using the script on talk pages or on WP pages is likely to result in more angst than benefit to the project.


== See also == == See also ==
*] * ]
*] * ]

Latest revision as of 10:06, 16 August 2024

Please leave a bug report or suggestion.
Shortcuts
Sidebar location of the script buttons after you have clicked on the 'Tools' triangle

Overview

This script delinks all dates and date fragments and converts them all to the same format, either dd mmm yyyy ("14 July 1978") or mmm dd, yyyy ("July 14, 1978").

MOSNUM allows one other format to be used in articles – but only in tables and reference sections.

NOTE: Functions converting dates within citation templates has been withdrawn now that MW software engine renders date formats automatically There are modes that allow the user to select whether to treat body dates only or body and reference sections:

  1. all dates to dmy – dates in the body of the text as well as in the reference sections are converted to "14 July 1978" or similar.
  2. all dates to mdy – as above. dates are converted to "July 14, 1978" or similar.
  3. Big endian ref dates button now disabled. Users are invited to manually add |cs1-dates= parameter to {{Use dmy dates}} or {{Use mdy dates}} causing applicable dates to be rendered in 2024-12-02 YMD format

In addition, there are the following modes to convert slash or contracted dates into the desired format:

  1. US-slash dates – converts dates that use slash or decimal separators in formats commonly used in the US into mdy dates viz: mm/dd/yy, mm/dd/yyyy, mm.dd.yy or mm.dd.yyyy
  2. UK-slash dates – converts dates that use slash or decimal separators in formats commonly used in the UK, Europe and elsewhere into dmy dates viz: dd/mm/yy, dd/mm/yyyy, dd.mm.yy or dd.mm.yyyy

* Note: In these latter 2 cases, false positives are more likely because the protection mechanism of the script is bypassed, meaning the regex will act on dates in instances other than where the |date= parameter is used

History

Lightmouse initially created a script to deal with a number of general formatting issues, and date alignment was one such function. I used it and often gave feedback and bug reports. Seeing the need to work on the diversity of date formats and date situations that are seen here on Misplaced Pages, I created an independent script targeted at dates with some help and advice from Lightmouse.

Over the years, this script has been built on and refined. In April 2012, the engine underwent a major rework by 1exec1 (talk · contribs), who built it and incorporated a new regex_worker function that allows more effective treatment of date fragments; there is better protection of strings that ought not to be modified by the script. In May, the new improved version of the script went 'live'.

Detailed functional overview

The dates script is at User:Ohconfucius/script/MOSNUM dates.js.

  • It is aimed to make displayed dates fully compatible with Misplaced Pages:Manual of Style (dates and numbers) (WP:MOSNUM)
  • It ensures uniform presentation of dates within any given article. As such, it:
    • delinks all dates and date fragments, including day-month strings, days, months, decades, centuries,
    • converts all these date fragments to the same format, either dd mmm yyyy or mmm dd, yyyy, at the option of the user
    • removes ordinal suffixes and constructions such as 'the 5th of September', 'December 25th' or 'October of 2003'
    • adds commas where necessary (e.g. February 28, 2001)
    • removes redundant commas (e.g. July, 1997; 28 February, 2001)
  • It removes direct links to dates and most forms of piped date links
  • It removes year linking templates (such as {{scy}}, {{by}}), and links to 'year-in X' where piped from years (such as ])
  • It converts other often used (but not MOSNUM-compliant) date formats within the references section, such as dd-mm-yyyy or dd-mmm-yyyy to the chosen prevailing format used in the rest of the article.
  • It makes certain fixes that may be identified as CS1 dates errors
  • It also allows users to choose to convert dates within only the body of the article, as is permitted for reference sections (where yyyy-mm-dd dates are common) to have different dates, or throughout the article. Now disabled. CS1 now manages the date rendering by auto-formatting citation template dates using parameters within the {{use dmy dates}} and {{use mdy dates}} templates, so this can be used to fine-tune the rendering.


The script adds or updates a non-displaying template {{use mdy dates}} or {{use dmy dates}} depending on the conversion used. This tagging allows for WM software engine to render date formats automatically in conformity with tagged format). It also facilitates future maintenance by bot by script AWB.

The script will achieve overall consistency of the format of the date. The format and syntax of citations were modelled after the way reference sections are rendered when using the most common citation templates – {{cite news}} and {{cite web}}; I try to stick to syntax in {{cite web}} where 'Retrieved' is capitalised and preceded by a full-stop.

Although the MediaWiki software interprets {{use dmy dates}} or {{use mdy dates}} templates, allowing dates and access dates within citation templates to be automatically formatted, errors there and elsewhere may still require correction. The script takes care of that.

How it works

The script is configured so that dates are stored as an array. The given regex and substitution strings can contain magic words that specify what date format the routine should accept and to what date format the routine should convert the date to.

There is a mechanism in place to protect a wide range of strings that ought to be immutable: such as images, categories, urls; text within blockquotes and double quotes; text within certain parameters (e.g. |title=). Occasionally, due to the proliferation of templates across en.wp, some may be the subject of unintended changes that have not been anticipated in the script regexes.

As also mentioned below, the actions of the protection mechanism can be revealed in the event of the script stalling, and substitution markers may appear in the edit window. When this occurs, the user should abandon the action, reopen the edit window and reperform the edit.

Optional auto-formatting citation template dates

Script default is without parameter, in which case date is aligned to the prevailing style, dmy or mdy.

Citation Style 1 and 2 (collectively cs1|2) templates automatically render dates (|date=, |access-date=, |archive-date=, etc) in the style specified by this template. Because it is allowed by WP:MOSDATES, the cs1|2 templates can automatically format dates in a variety of styles. Editors may choose how cs1|2 templates render dates by the use of |cs1-dates=<keyword>.

Acceptable |cs1-dates= keywords
Keyword Definition
l long-form publication and access- / archive-dates;
this is the default case when |cs1-dates= is omitted or empty
ll
ls long-form publication dates; abbreviated access- / archive-dates
ly long-form publication dates; year-initial numeric access- / archive-dates (ymd)
s abbreviated publication and access- / archive-dates
ss
sy abbreviated publication dates; year-initial numeric access- / archive-dates (ymd)
y year-initial numeric publication, access- and archive-dates (ymd);
cs1|2 cannot reformat Month YYYY, Season YYYY, date-ranges of any form, or Julian calendar dates into ymd format
yy

An example is given at Help:Citation Style 1 § Auto-formatting citation template dates.

Credits

I am solely responsible for this tool, which has been inspired by the dates scripts written by User:Lightmouse and User:Plastikspork. It incorporates many additional features, such as unlinking many unusually-piped date-links, conversion of date series and ranges, and delinking months of the year. Thanks also to User:1exec1 for the invaluable assistance in rewriting and simplifying the workings of the script in April 2012.

Feedback is appreciated at User Talk:Ohconfucius. Please report any false negatives as well as false positives you may detect.

Installing the script

  1. Open your common.js in edit mode (alternatively, go to your user page and append "/common.js" to the end of the URL and open the page in edit mode).
    • If you prefer to load this only on a specific skin, such as monobook, open your monobook.js in edit mode.
    • If you make a straight copy of this script, instead of "importing" it, you may not benefit from the enhancements and bug-fixes that are made from time to time. In the latter case, you may choose to watchlist this page so you will know when to update your copy for modifications to this script.
  2. Copy the following code onto the JavaScript page you have chosen in the previous step:
    importScript('User:Ohconfucius/script/MOSNUM dates.js'); // ]
    
  3. Save the page and (re-)load it – refresh the cache by following the instructions at the top of your JavaScript page.
  4. Bookmark the script page. This will be your cue to purge the cache on your browser for any updates to take effect.

Disclaimer: Use at your own risk and make sure you check the edit changes before you save.

Actions and test

Use of the Safari or Firefox browsers is highly recommended. It only functions in desktop mode.

The script is continually being run and seems to work as intended on the latest Firefox and Chrome browsers on Mac and Windows. On Windows machines, browser-specific issues for IE, specifically version 8 have been reported. These may or may not have been resolved.

The tool may also be used on mobile browsers. However, extensive testing has not been undertaken.

Once you are in edit mode, there are buttons in the toolbox in the left margin:

  1. DATES to dmy – converts all dates to 2 December 2024 dmy format
  2. DATES to mdy – converts all dates to December 2, 2024 mdy format
  3. US-slash dates – converts all applicable dates into December 2, 2024 mdy format
  4. UK-slash dates – converts all applicable dates into 2 December 2024 dmy format
Notes

Users are equally reminded of the following provisions of Misplaced Pages:Manual of Style (dates and numbers):

Format consistency
  • Dates in article body text should all use the same format: Julia ate a poisoned apple on 25 June 2005, and died on 28 June (not ... on June 28).
  • Publication dates in references should all use the same format. Any format from the "Acceptable date formats" table above may be used unless the citation style being used requires a different format (however, all-numeric date formats other than yyyy-mm-dd must still be avoided).
  • Access and archive dates in references should all use the same format – either the format used for publication dates or yyyy-mm-dd

(These consistency requirements apply to dates in general prose and reference citations, but not to dates in quotations or titles)

Strong national ties to a topic
Shortcuts
  • Articles on topics with strong ties to a particular English-speaking country should generally use the more common date format for that nation. For the United States, this is month before day; for most others, it is day before month. Articles related to Canada may use either format consistently.
  • Sometimes the customary format differs from the usual national one: for example, articles on the modern US military use day before month, in accordance with military usage.
Retaining the existing format
Shortcut
  • If an article has evolved using predominantly one format, the whole article should conform to it, unless there are reasons for changing it based on strong national ties to the topic or consensus on article talk.
  • The date format chosen by the first major contributor in the early stages of an article should continue to be used, unless there is reason to change it based on strong national ties to the topic or consensus on article talk.
  • Where an article has shown no clear sign of which format is used, the first person to insert a date is equivalent to "the first major contributor".

Test pages

Known limitations

  • Proper nouns with dates: A number of proper nouns containing date fragments (such as 'March 14 Alliance', '6th of October City', 'June 1, 1974', '2000 AD') have been specifically protected from conversion or delinking. Only the displayed part of piped links are acted upon, whilst the underlying pipe will not be changed. For the purposes of this script, September 11 or September 11 attacks is treated: there are ample redirects in existence for any problems to be mitigated. Let me know if there are other proper names which ought to be protected.
  • Dates that are used as adjectives: Because the script routinely removes the leading "the" for dates, attention should be paid to where the date is used as an adjective, such as "the 6 June beach landings". The "the" should either be reinserted, or the phrase reconfigured so that the date is no longer adjectival (e.g. "the beach landings on 6 June").
  • Stalling: If you see characters such as the following in your diffs window, don't panic:
⍌190⍍
⍌191⍍
this is simply the result of a stalling of the script, where the protected strings haven't been restored by the time you see the changes displayed on screen. It happens occasionally. In such a case, you should abandon the edit by refreshing the edit window, and then click on the script button again.

Known conflicts

Other Wiki scripts or gadgets

  • wikEd: The script is known to conflict with wikEd that prevents the MOSNUM dates script from making any changes to articles, or simply blocking the creation of a script button. The solution is to toggle the wikEd text area off while running MOSNUM dates. wikEd has an easy toggle button for that called: Use wikEd instead of classic text area. Simply press the toggle button so the button pops out (off), then run MOSNUM dates. When you are done running MOSNUM dates you can press the toggle button again so the toggle button pops in (on) and the wikEd text area will be live again. Once you get in the habit of toggling the wikEd text area on and off, running MOSNUM dates is no longer a conflict with wikEd. There is no need to disable/re-enable wikEd in your common.js file.

Browsers

Disclaimers

I use and make experimental changes to another version, and update this production version regularly to a suitably stable prior version of the test script. However, like all software, bugs are unavoidable. Use at your own risk, and make sure you check the edit changes before you save. The script is continually being run and seems to work as intended on the latest Firefox and Chrome browsers. However, browser-specific issues have been reported for IE on Windows machines in the past (as at 1 January 2019, there are no recent reports of such compatibility issues).

By consensus, this script should not be used in articles about chronological periods, such as 2015 or January 25, as date links here, considered desirable, would otherwise be automatically removed. Equally, I suspect that using the script on talk pages or on WP pages is likely to result in more angst than benefit to the project.

See also