User:Pathoschild/script/MOSNUM dates.js: Difference between revisions

Content deleted Content added
migrate to TemplateScript
switch to now-updated MOSNUM utils script
 
(2 intermediate revisions by the same user not shown)
Line 7:
$.when(
$.ajax("//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js", { dataType: "script", cache: true }),
$.ajax("//en.wikipedia.org/w/index.php?title=User:PathoschildOhconfucius/script/MOSNUM_utils.js&action=raw&ctype=text/javascript", { dataType: "script", cache: true })
).then(function() {
pathoschild.TemplateScript.add(
Line 53:
*/
function ohc_extend_editor(editor) {
editor.ohc_regex = function(rg, sub, func) {
{
var text = editor.get();
text = ohc.dateutil.regex(text, rg, sub, func);
Line 98 ⟶ 97:
 
// resolvable ambiguous date formats
.ohc_regex(/([^-\d/:\.])@MM\/@DD\/@YYNN(?=[^-–/\w&])/gi, '"$1@Month @Day, @YYYY'")
.ohc_regex(/([^-\d/:\.])@MM\.@DD\.@YYNN(?=[^-–/\w&])/gi, '"$1@Month @Day, @YYYY'")
.ohc_regex(/([^-\d/:\.])@MM[-–]@DD[-–]@YYNN(?=[^-–/\w&])/gi, '"$1@Month @Day, @YYYY'")
.ohc_regex(/(\| ?)@MM\/@DD\/@YYNN(?=\s*\|)/gi, '"$1@Month @Day, @YYYY'")
.ohc_regex(/(\| ?)@MM\.@DD\.@YYNN(?=\s*\|)/gi, '"$1@Month @Day, @YYYY'");
//.ohc_regex(/(\| ?)@MM[-–]@DD[-–]@YYNN(?=\s*\|)/gi, '"$1@Month @Day, @YYYY'");
}
 
Line 115 ⟶ 114:
 
// resolvable ambiguous date formats
.ohc_regex(/([^-\d/:\.])@DD\/@MM\/@YYNN(?=[^-–/\w&])/gi, '"$1@Day @Month @YYYY'")
.ohc_regex(/([^-\d/:\.])@DD\.@MM\.@YYNN(?=[^-–/\w&])/gi, '"$1@Day @Month @YYYY'")
.ohc_regex(/([^-\d/:\.])@DD[-–]@MM[-–]@YYNN(?=[^-–/\w&])/gi, '"$1@Day @Month @YYYY'")
.ohc_regex(/(\| ?)@DD\/@MM\/@YYNN(?=\s*\|)/gi, '"$1@Day @Month @YYYY'")
.ohc_regex(/(\| ?)@DD\.@MM\.@YYNN(?=\s*\|)/gi, '"$1@Day @Month @YYYY'");
//.ohc_regex(/(\| ?)@DD[-–]@MM[-–]@YYNN(?=\s*\|)/gi, '"$1@Day @Month @YYYY'");
}
 
Line 134 ⟶ 133:
editor
// add missing space between wikilinks
.replace(/(\]\])(\[\[)/gi, '"$1 $2'") // remove (?!file:) to ensure a space between all links
 
// rem redundant quote marks and parentheses
Line 163 ⟶ 162:
 
// remove nowrap template from dm and md dates
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@DD(?:[ _]| )@Month)( @yyyy|)\}\}/gi, '"$1@DD @LMonth$2'")
.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@Month(?:[ _]| )@DD)( @yyyy|)\}\}/gi, '"$1@LMonth @DD$2'")
 
// delink single dm or 'dth the m'
Line 190 ⟶ 189:
 
// century
.replace(/\[\[((?:first|second|third|(?:four|fif|six|seven|eigh|nin|ten|eleven|twelf|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twentie)th|twenty[\s\-]first[\s\-])centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE))?)\]\]/gi, '"$1'")
.replace(/\[\[(?:first|second|third|(?:four|fif|six|seven|eigh|nin|ten|eleven|twelf|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twentie)th|twenty[\s\-]first)[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE))?\|([^\]]{1,30})\]\]/gi, '"$1'")
.replace(/\[\[(\d{1,2}(?:st|[nr]d|th))[\s\-_](centur(?:y|ies))(\s(?:AD|BC|CE|BCE)|)\]\]/gi, '"$1 $2$3'")
.ohc_regex(/\[\[\d{1,2}@th[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE)|)\|([^\]]{1,30})\]\]/gi, '"$1'")
 
// months
Line 200 ⟶ 199:
 
// decades and years
.replace(/(\d{1,3}0)[‘`´’′]?s/g, '"$1s'")
.replace(/\[\[(\d{1,3}0)\'?s\]\]/g, '"$1s'")
.replace(/\[\[\d{1,3}0\'?s?\|([^\]]{1,30})\]\]/g, '"$1'")
.replace(/\[\[(\d{1,3}0)\'?(s)?\s(AD|BC|CE|BCE)\]\]/gi, '"$1$2 $3'")
.replace(/\[\[(\d{1,4}[\s_]?)(AD|BC|CE|BCE)\]\]/gi, '"$1$2'")
.replace(/\[\[(AD|BC|CE|BCE)([\s_]?)(\d{1,4})\]\]/gi, '"$1$2$3'")
.ohc_regex(/([-–])\[\[\s?@yyyy\s?\|\s?(\d{2,4})\s?\]\]/gi, '"$1$2'") // piped year
.replace(/\[\[([12]\d{3}|[1-9]\d{0,2})\]\]/gi, '"$1'")
.replace(/\[\[\d{1,3}0\'?s?\s(?:AD|BC|CE|BCE)\|([^\]]{1,30})\]\]/gi, '"$1'")
.replace(/\[\[\d{1,3}0\'?s?\s\(decade\)\|([^\]]{1,30})\]\]/gi, '"$1'")
 
// month+year
Line 224 ⟶ 223:
 
// removed piped years when in full date (excepting disambiguated parentheses - updated 24/2/2012)
//.ohc_regex(/\[\[[^|\]\(\)]{1,32}\|@YYYY\]\]/gi, '"@Year'"); // 23/6/2021 – disabled delinking "other" year-in articles
 
// Identify surprise or 'Easter egg' diversions linking months to year or "year in" articles.
.ohc_regex(/\[\[\d{1,4}#[^|\]]+\|@Month\]\]/gi, "@LMonth")
.ohc_regex(/\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi, '"@Year'")
 
// month and day piped
Line 236 ⟶ 235:
 
// years piped
.replace(/\[\[\d{1,4}\|([^\]]{1,30})\]\]/gi, '"$1'");
}
 
function ohc_fix_common_errors(editor) {
editor
.ohc_regex(/(\d)<sup>@th<\/sup>/gi, '"$1th'")
 
// remove dashbot comment from dates
.replace(/<!-- ?DASHBot ?-->/gi, '')
.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*c(?:irca|a\.)?\s?((?:@day |)@month @year)(?=[\s\n]*[<|}])/gi, '"$1c. $2'") // add space
 
// common cs1 errors
.replace(/(\|\s*(?:date|year)\s*=)\s*(1[7-9]\d|20[0-1])\?(?=[\s\n]*[<|}])/gi, '"$1c. $20'")
.replace(/(\|\s*(?:date|year)\s*=\s*(1[7-9])\d{2})[-–](\d{2})(?=[\s\n]*[<|}])/gi, '"$1–$2$3'")
//.replace(/(\|\s*(?:date|year)\s*=\s*(20)[0-1]\d)[-–]([0-2]\d)(?=[\s\n]*[<|}])/gi, '"$1–$2$3'")
.ohc_regex(/(\|\s*(?:date|year)\s*=\s*)@YYYY\s*[-–/]\s*@YYNN(?=[\s\n]*[<|}])/gi, '"$1@YYYY1–@YYYY2'") // common cs1 error(/(\|\s*(?:date|year)\s*=\s*)@YYYY\s*[-–/]\s*@YYYY(?=[\s\n]*[<|}])/gi, '"$1@YYYY1–@YYYY2'") //common cs1 error
.replace(/(\|\s*(?:date)\s*=)\s*s(pring|ummer),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi, '"$1S$2 $3'") // common cs1 error
.replace(/(\|\s*(?:date)\s*=)\s*a(utumn),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi, '"$1A$2 $3'") // common cs1 error
.replace(/(\|\s*(?:date)\s*=)\s*f(all),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi, '"$1F$2 $3'") // common cs1 error
.replace(/(\|\s*(?:date)\s*=)\s*w(inter),?\s*((?:1[7-9]\d|20[0-1])\d)(?=[\s\n]*[<|}])/gi, '"$1W$2 $3'") // common cs1 error
.replace(/(\|\s*(?:date)\s*=)\s*(Spring|Summer|Autumn|Fall|Winter)[-–](S(?:pring|ummer)|Autumn|Fall|Winter) ?/gi, '"$1$2–$3 '") // common cs1 error
.ohc_regex(/(\|\s*access-?date\s*=)\s*(@month @year)(?=[\s\n]*[<|}])/gi, '"$11 $2'") //common cs1 error
//.ohc_regex(/(\|\s*date\s*=\s*)@year\?(?=[\s\n]*[<|}])/gi, '"$1@Year'") // common cs1 error
//.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*@year\?(?=[\s\n]*[<|}])/gi, '"$1c. @Year'") // common cs1 error
//.ohc_regex(/(\|\s*(?:date|year)\s*=)\s*(@month @year)\?(?=[\s\n]*[<|}])/gi, '"$1c. $2'") // common cs1 error
.ohc_regex(/(\|\s*access-?date\s*=)\s*@month @day, (1[7-9]\d{2}|2000)(?=[\s\n]*[<|}])/gi, '"$1'") // rem access date before Wikipedia (January 2001)
.ohc_regex(/(\|\s*access-?date\s*=)\s*@day @month.? (1[7-9]\d{2}|2000)(?=[\s\n]*[<|}])/gi, '"$1'") // rem access date before Wikipedia (January 2001)
.ohc_regex(/(\|\s*access-?date\s*=)\s*31( (?:April|June|September|November) @year)(?=[\s\n]*[<|}])/gi, '"$130$2'") // rem nonsense access date (short months)
.ohc_regex(/(\|\s*access-?date\s*=)\s*29( February (?:200[1235679]|201[1345789]))(?=[\s\n]*[<|}])/gi, '"$128$2'") // rem nonsense access date 29 Feb (non-leap year)
.ohc_regex(/(\|\s*access-?date\s*=)\s*(?:3[01])( February @yyyy)(?=[\s\n]*[<|}])/gi, '"$128$2'") // rem nonsense access dates February
.replace(/(\|\s*access-?date\s*=)\s*(\d{4})(?=[\s\n]*[<|}])/gi, '') // common cs1 error
 
Line 272 ⟶ 271:
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@YYYY-@DD-@Mon/gi, "$1 @DD @FullMonth @YYYY")
 
.replace(/(\|\s*(?:date|year)\s*=)\s*(?:(?:date |)unknown|(?:not? |non-|un)date[ds])(?=[\s\n]*[<|}])/gi, '"$1n.d.'") // common cs1 error
.replace(/(\|\s*(?:date|year)\s*=)\s*n\.?d(?=[\s\n]*[<|}])/gi, '"$1n.d.'") // common cs1 error
.replace(/(\|\s*)year(\s*=\s*)(?=n\.?d\.)(?=[\s\n]*[<|}])/gi, '"$1date$2'") // common cs1 error
 
// remove parasitic metadata - days of the week/descriptives
Line 288 ⟶ 287:
 
// remove deprecated parameters (|day= and |month)
.ohc_regex(/(\|\s*)day(?:\s*=\s*)@DD ?\| ?month(?:\s*=\s*)@Month ?\| ?year(?:\s*=\s*)@YYYY(?=[|}\s])/gi, '"$1date=@Day @Month @Year'")
.ohc_regex(/(\|\s*)year(?:\s*=\s*)@YYYY ?\| ?month(?:\s*=\s*)@Month ?\| ?day(?:\s*=\s*)@DD(?=[|}\s])/gi, '"$1date=@Month @Day, @Year'")
 
// typos
.ohc_regex(/(date *= *)@Day @Month ?@th/gi, '"$1@Day @Month'")
.ohc_regex(/(date *= *)@Day @Month\w(?= \d{3,4})/gi, '"$1@Day @Month'")
 
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )(Jan|Febr)[\w ]?[aur]{3,4}\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1$2uary'")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )J[anu]{3,5}r\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1January'")
.ohc_regex(/(date *= *(?:[12]?\d) )Febua?r\w{0,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1February'")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )M\w{2,3}ch(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1March'")
.ohc_regex(/(date *= *(?:[12]?\d|30) )A[bpv\[]\w{2,3}l\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1April'")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )Ma[tui](?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1May'")
.ohc_regex(/(date *= *(?:[12]?\d|30) )J\wn\w(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1June'")
.ohc_regex(/(date *= *(?:[12]?\d|30) )J\w{1,2}e(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1June'")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )Jul\w{1,2}(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1July'")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )A[oug]{2,3}\w{1,4}t(?:\w|us)?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1August'")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )(Sept|Nov|Dec)\w{2,4}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1$2ember'")
.ohc_regex(/(date *= *(?:[12]?\d|30) )S\w{0,2}p[ \[]?\w{2,5}[er]{2,3}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1September'")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )O\w{0,2}t\w{1,3}[er]{2,3}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1October'")
.ohc_regex(/(date *= *(?:[12]?\d|30) )[MN]\w{1,2}[bv] ?\w{1,3}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1November'")
.ohc_regex(/(date *= *(?:[12]?\d|30|31) )D[ie]?[cs] ?\w{1,4}b[er]{1,2}\w?(?= (?:1[6-9]\d|20[01])\d\b)/gi, '"$1December'")
 
.ohc_regex(/(date *= *)@Month\w(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1@Month'") //rem stray digit at the end of year string
 
.ohc_regex(/(date *= *)(Jan|Febr)[\w ]?[aur]{3,4}\w{0,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1$2uary'")
.ohc_regex(/(date *= *)J[anu]{3,5}r\w{0,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1January'")
.ohc_regex(/(date *= *)Febua?r\w{0,2}(?=(?: (?:[12]?\d),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1February'")
.ohc_regex(/(date *= *)M\w{2,3}ch(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1March'")
.ohc_regex(/(date *= *)A[bpv\[]\w{2,3}l\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1April'")
.ohc_regex(/(date *= *)Ma[tui](?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1May'")
.ohc_regex(/(date *= *)J\wn\w(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1June'")
.ohc_regex(/(date *= *)J\w{1,2}e(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1June'")
.ohc_regex(/(date *= *)Jul\w{1,2}(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1July'")
.ohc_regex(/(date *= *)A[oug]{2,3}\w{1,4}t(?:\w|us)?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1August'")
.ohc_regex(/(date *= *)(Sept|Nov|Dec)\w{2,4}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1$2ember'")
.ohc_regex(/(date *= *)S\w{0,2}p[ \[]?\w{2,5}[er]{2,3}\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1September'")
.ohc_regex(/(date *= *)O\w{0,2}t\w{1,3}[er]{2,3}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1October'")
.ohc_regex(/(date *= *)[MN]\w{1,2}[bv] ?\w{1,3}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1November'")
.ohc_regex(/(date *= *)D[ie]?[cs] ?\w{1,4}b[er]{1,2}\w?(?=(?: (?:[12]?\d|30|31),?|) (?:1[6-9]\d|20[01])\d\b)/gi, '"$1December'")
 
// insert comma to separate date from army unit
Line 350 ⟶ 349:
 
// remove extraneous bracket //from Batty
.ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:archive-?|access-?|publication-?)?date\s*=\s*)([\w\s-]+)\](?=\s*[\|}<])/gi, '"{{$1$2$3$4'")
 
// fix bda template redirect
//.replace(/\{\{bda\|([^}]+)\}\}/gi, '"{{birth date and age|$1}}'")
//.replace(/\{\{dda\|([^}]+)\}\}/gi, '"{{death date and age|$1}}'")
 
// zap redundant {{date}}, {{accessdate}} {{retrieved}}, {{monthname}} and {{#dateformat}}
Line 360 ⟶ 359:
.ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:[^\}]*)}}/gi, "@Day @Month @YYYY")
.replace(/{{#formatdate:([^}]+)}}/gi, "$1")
.replace(/\{\{#dateformat:([^}\|]+)(?:\|dmy|\|mdy)?\}\}/gi, '"$1'")
//.ohc_regex(/(date[ ]*=[ ]*)\{\{(?:Start|End) ?date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\|@DD(?:\|df=y(?:es|)|)\}\}/gi, '"$1@Month @DD, @YYYY'") // stripping start/end template notes inside "|date=" parameter (line 72)
.ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:\|(?:[dmy]{3}|iso)|)}}/gi, "@Day @Month @YYYY")
.ohc_regex(/\|\s*(?:archive|access|air)-?date\s*=\s*\{\{date\}\}(?=\s*[|}])/gi, "") //remove {{date}} template without parameters that inappropriately return crrent date
Line 367 ⟶ 366:
.ohc_regex(/\{\{date\|@YYYY\/@MM\/@DD\}\}/gi, "@YYYY-@MM-@DD") //remove {{date}} template while rectifying slash dates within the template
.ohc_regex(/\{\{date\|(@DD[\-\s]@Mon|@Mon[\-\s]@DD)\}\}/gi, "@Day @Month")
.replace(/\{\{date\|([^}\|]+)(?:\|l?(?:[dmy]{3}|iso|none|link))?\}\}/gi, '"$1'")
.ohc_regex(/[ ]*\{\{accessdate\|@YYYY-@MM-@DD[ ]*\}\}/gi, " Retrieved @YYYY-@MM-@DD")
.ohc_regex(/[ ]*\{\{retrieved[ ]*\|[ ]accessdate=([\-\w, ]*)\}\}/gi, " Retrieved $1")
//.ohc_regex(/(date[ ]*=[ ]*|\w{2,}[ ]*)\{\{(?:start|end).date[^|}]*(?:\|df=y(?:es|)|)\|@YYYY(?:\|df=y(?:es|)|)\}\}/gi, '"$1@YYYY'") // stripping start/end template (disabling to placate Pigsonthewing)
//.ohc_regex(/\{\{(?:Start|End) date(?:\|df=y(?:es|)|)\|@YYYY\|@MM\}\}/gi, '"@Month @YYYY'") // tripping start/end template notes
//.ohc_regex(/<!--(?:Use)? \{\{(?:Start|End) date\|@YYYY\|@MM\|@DD\}\} -->/gi, '') // stripping start/end template notes
.ohc_regex(/(\{\{MONTHNAME\|@MM\}\})/gi, "@Month")
 
// expand one and two-digit years in ranges
.replace(/(\()@Month @YYYY[-–]@Month @YYNN(\))/gi, '"$1@Month1 @YYYY1 – @Month2 @YYYY2$2'")
.replace(/(\(1[789])(\d)(1)[-–]([2-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(1[789])(\d)(2)[-–]([3-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(1[789])(\d)(3)[-–]([4-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(1[789])(\d)(4)[-–]([5-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(1[789])(\d)(5)[-–]([6-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(1[789])(\d)(6)[-–]([7-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(1[789])(\d)(7)[-–]([8-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(1[789])(\d)(8)[-–](9\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(20)([01])(1)[-–]([2-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(20)([01])(2)[-–]([3-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(20)([01])(3)[-–]([4-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(20)([01])(4)[-–]([5-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(20)([01])(5)[-–]([6-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(20)([01])(6)[-–]([7-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(20)([01])(7)[-–]([8-9]\))/gi, '"$1$2$3–$2$4'")
.replace(/(\(20)([01])(8)[-–](9\))/gi, '"$1$2$3–$2$4'")
 
.ohc_regex(/(\W)@DD@th?, @DD@th?((?:[ ]|&nbsp;)(?:and|&|to|or)(?:[ ]|&nbsp;))@DD@th?(?:\sof\s?)?([ ]|&nbsp;)@Month(?=\W)/gi, '"$1@Day1, @Day2$2@Day3$3@LMonth'")
.ohc_regex(/(\W)@DD@th?((?:[ ]|&nbsp;)(?:and|&|to|or)(?:[ ]|&nbsp;))@DD@th?(?:\sof\s?|)([ ]|&nbsp;)@Month(?=\W)/gi, '"$1@Day1$2@Day2$3@LMonth'")
.ohc_regex(/(\W)the @DD@th(?:\sof|)\s@Month,? @YYYY(?=\W\D)/g, '"$1@Day @LMonth @YYYY'")
.ohc_regex(/(\W)the @DD@th(?:\sof|)\s@Month(?=\W\D)/g, '"$1@Day @LMonth'")
.ohc_regex(/(\W)@Day@th?(?:\sof|)([ _]|&nbsp;|{{(?:break|nbsp)}})@Month(?=[^|\]\w])/gi, '"$1@Day$2@LMonth'")
.ohc_regex(/(\W)@Month\s(?:the\s)?@DD@th?,(?:\sthe\s)?(?: |&nbsp;)@DD@th?(\s(?:and|&|to|or)(?:[ _]|&nbsp;))(?:the\s)?@DD@th?(?=[^|\]\w])/gi, '"$1@LMonth @Day1, @Day2$2@Day3'")
.ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?:,?(?:[ _]|&nbsp;)|\sof\s)?(\d{3,4}\W\D)/gi, '"$1$2 $3$4$5@Day, $6'")
.ohc_regex(/(\W)(@month)\s(@day)((?:,\s@day){0,6}),?(\/|\s?[-–]\s?|\s(?:and|&|to|or)\s+?)@Day@th?(?=\W\D)/gi, '"$1$2 $3$4$5@Day'")
.ohc_regex(/(\W)@Month([ _]|&nbsp;|{{(?:break|nbsp)}})(?:the\s)?@DD@th?,? @Year/gi, '"$1@LMonth$2@Day, @Year'")
.ohc_regex(/(\W)@Month @Day(?:\sof|,|)([ _]|&nbsp;|{{(?:break|nbsp)}})@Year(?=[^|\]\w])/gi, '"$1@Month @Day,$2@Year'")
 
// consolidating/amalgamating date fields
Line 412 ⟶ 411:
// eliminating dates and time placed in author parameter
// removing artefacts from Indian news sites (TNN Aug 30, 2012, 05.46AM)
.ohc_regex(/(\|\s*author\s*=\s*(?:[A-Z]{2,3}\b))(?:[^|}]*)\d{4}, [\d\.:]{4,5}(&nbsp;|)[AP]M IST(?=[ ]*\|)/g, '"$1$2'")
//.ohc_regex(/(\|\s*author=(?:[^\[\]|{}]*))(TNN|PTI) @day @month @yyyy, [\d\.:]{4,5}(&nbsp;|)[AP]M IST(?=[ ]*\|)/g, '"$1$2'")
 
.ohc_regex(/(\|\s*author\s*=\s*)@month @day,? @yyyy\s?(?:,? [0-2]?\d[\.:][0-5]\d(?:\s*|&nbsp;)(?:[apAP][mM]\s*|)(?:GMT\s*|UTC\s*|[A-Z]{1,2}[DS]T\s*|)|)(?=\|)/g, "$1")
Line 452 ⟶ 451:
.ohc_regex(/([ =|])@DD\.@MM\.@YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/([ =|])@DD @MM @YYYY(?=[^-–\d/])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@DD[-–\/\.=\s]@Month[-–\/\.=\s]@YYNN(?=\s*[|}\n])/gi, '"$1@Day @Month @YYYY'")
 
//convert yyyy-dd-mm to yyyy-mm-dd
.ohc_regex(/{{(\s*[Cc]it(?:e|ation))([^}]+)(\s*\|\s*(?:publication|archive|access|air|)-?date\s*=\s*(?:1[0-9]|20)\d{2})[-/\.=\s](1[3-9]|2\d|3[01])[-/\.=\s](0?\d|1[0-2])(\s*[\|}<])/gi, '"{{$1$2$3-$5-$4$6'") // from Batty
 
// eliminating other errant formats
Line 462 ⟶ 461:
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month ?@Day,? ?200([01]\d)[^\s|}]?(?=\s*[|}])/gi, "$1@Month @Day, 20$2")
 
.ohc_regex(/([ ]\()@DD-@MM-@YYYY(\)\W)/gi, '"$1@Day @Month @YYYY$2'")
.ohc_regex(/([ ]\()@DD-@Month-@YYYY(\)\W)/gi, '"$1@Day @Month @YYYY$2'")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@Month, @DD, @YYYY(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
.ohc_regex(/(\|(?:[\w ]*)date\s*=\s*)@DD[\.,] @Month,? @YYYY(?=\s*[|}])/gi, "$1@Day @Month @YYYY")
Line 491 ⟶ 490:
.ohc_regex(/(\W)@FullMonth\s@DD(\s+|\s*,)/gi, "$1@FullMonth @Day$2")
.ohc_regex(/(\W)@Mon\s@DD(\s+|\s*,)/gi, "$1@Mon @Day$2")
.replace(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?=[ ]*(=|BC|AD|CE))/g, '"$1c$2'")
//.replace(/(\d(?:st|nd|rd|th) )C(entur(?:ies|y))(?![ \-][A-Z]\w*|''|")/g, '"$1c$2'")
 
//spaces and commas - in date formats
Line 548 ⟶ 547:
editor
// multiple calls for multiple dates within single citation
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '"$1@Day @Month @YYYY$2'")
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '"$1@Day @Month @YYYY$2'")
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '"$1@Day @Month @YYYY$2'");
}
 
Line 557 ⟶ 556:
editor
// multiple calls for multiple dates within single citation
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '"$1@Month @Day, @YYYY$2'")
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '"$1@Month @Day, @YYYY$2'")
.ohc_regex(/([^-\w/])@YYYY[-–]@MM[-–]@DD([^-\w/])/gi, '"$1@Month @Day, @YYYY$2'");
}
 
Line 567 ⟶ 566:
 
editor
.replace(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, '"$1@Day @Month @Year$2'")
.ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi, '"$1{{dts|format=dmy|@YYYY|@MM|@DD}}$2'") // dts template for sortable tables
.ohc_regex(/(\{\{dts\|format=)mdy\|/gi, '"$1dmy|'"); //flip dts template formats
}
 
Line 577 ⟶ 576:
 
editor
.replace(/([^\w\/\-%,])@YYYY-@MM-@DD(<\s?\/ref.*?>)/g, '"$1@Month @Day, @Year$2'")
.ohc_regex(/(\|\|[ ]*)@YYYY[-–]@MM[-–]@DD([ ]*\|\|)/gi, '"$1{{dts|@YYYY|@MM|@DD}}$2'") // dts template for sortable tables (mdy is default)
.ohc_regex(/(\{\{dts\|)format=(?:mdy|dmy|) ?\|/gi, '"$1'"); // flip dts template formats
}
 
Line 586 ⟶ 585:
//.ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|(@year)\}\}/gi, "$1") // disabled 3/5/21 discussion at https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Baseball&oldid=1021203365#Links_to_baseball_year_articles_in_infobox?
//.ohc_regex(/\{\{(?:avyear|by|baseball\syear|fy|ly|mlby|mlb\syear|scy|sdy)\|@year\|(@year)\}\}/gi, "$1")
.ohc_regex(/\[\[@yyyy\sin\s[^|\]]+\|((?:(?:@day |)@month |)@yyyy)\]\]/gi, '"$1'")
.replace(/\[\[(?:\d{4}[-–]\d{2} in English football)\|((?:(?:@Day |)@Month |)@YYYY)\]\]/gi, '"$1'")
 
.replace(/\[\[\d{4} Major League Baseball season\|(\d{4})(\sseason)?\]\]/gi, '"$1$2'");
}
 
Line 598 ⟶ 597:
// dts - format=dmy in this case (per D12000)
// per {{dts}} doc, remove the obsolete link=off param
.replace(/(\{\{dts[^}]*)(?:\|link=off)/gi, '"$1'")
.ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\|\s*format=)(?:dmy|mdy)(\}\})/gi, '"$1'"+format+'"$2'")
.ohc_regex(/(\{\{dts\s*\|\s*format=)(?:dmy|mdy)(\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*\}\})/gi, '"$1'"+format+'"$2'")
.ohc_regex(/(\{\{dts\s*\|\s*@year\s*\|\s*@month\s*\|\s*@day\s*)(\}\})/gi, '"$1|format='"+format+'"$2'")
 
// stripping – {{dts}} serves no purpose inside date parameters
Line 615 ⟶ 614:
// GR - date formatting parameter
// per {GR} doc, insert date formatting param
.replace(/(\{\{GR\|\d\d?)(?!\|date)/gi, '"$1|dateform='" + format);
}
 
Line 621 ⟶ 620:
editor
.replace(/\|df=[mdy]{3}(?:-all|)(?=\s*[|}])/gi, '')
.replace(/\|format=mdy/gi, '"|format=dmy'")
 
// change start and end templates; vgrelease new v=2 or mdy is default
.replace(/(\{\{(?:start date|end date)[^|}]*\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '"$1$2'")
.replace(/(\{\{vgrelease new[^|}]*\|)(?:v=1\||)([A-Z]{2,3}\|)/g, '"$1v=2|$2'")
.ohc_regex(/(\|\s*(?:begin|end|first|last)\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Day @Month @YYYY") // spotted at [[Template:Infobox recurring event]]
 
// change birth and death templates
.replace(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start)[^}]*\|)m(f=ye?s?)/gi, '"$1d$2'") // substitute df for mf
.replace(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start|film ?date|Wayback)[\|\d]+)(\}\})/gi, '"$1|df=y$2'") // insert df parameter
.replace(/(\{\{(?:(?:Birth|Death) date(?: and age|)|launch|release|start|film ?date|Wayback)[\|\d]+\|)df=ye?s?\|([^}]*df=ye?s?)/gi, '"$1$2'") // put date format parameter at the end
.replace(/(\{\{(?:start date|end date)\|)df=ye?s?\|((?:1[789]|20)\d{2}\}\})/gi, '"$1$2'") // date format parameter not needed – year only
 
// convert date ranges (md,d,d-dy to d,d,d-dmy; md,d,d-d to d,d,d-dm; md,d,d to d,d,dm)
Line 655 ⟶ 654:
 
//dates with embedded nbsp
.ohc_regex(/(\D\W)@Month([ _]|&nbsp;)(\d{1,2},(?: |&nbsp;)\d{1,2}(?:\s(?:and|&|to|or)(?:[ _]|&nbsp;))\d{1,2})(?=[^|\]\w])/gi, '"$1$3$2@LMonth '")
.ohc_regex(/(\D\W)@Month([ _]|&nbsp;|{{(?:break|nbsp)}})@Day,([ _]|&nbsp;|{{(?:break|nbsp)}})@YYYY(?=[^|\]\w])/gi, '"$1@Day$2@Month$3@Year'")
 
//remove comma
Line 673 ⟶ 672:
.replace(/\|df=[mdy]{3}(?:-all|)(?=\s*[|}])/gi, '')
.replace(/\|df=y(?:es|)(?=[|}\s])/gi, '')
.replace(/(mf=y(?:es|)\|[^}]*\|)(?:mf=y(?:es|)\|)/gi, '"$1'")
.replace(/(\{\{vgrelease new[^|}]*\|)(?:v=2\||)([A-Z]{2,3}\|)/g, '"$1$2'")
.ohc_regex(/(\|\s*(?:begin|end|first|last)\s*=\s*)@YYYY[-–]@MM[-–]@DD(?=\W\D)/gi, "$1@Month @Day, @YYYY")
 
Line 744 ⟶ 743:
function ohc_expand_all_dates(editor) {
editor
.ohc_regex(/([^-\w/])@Month @YYYY(?=[^-\w/])/gi, '"$1@FullMonth @YYYY'")
.ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi, '"$1@Day @FullMonth @YYYY'")
.ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi, '"$1@FullMonth @Day, @YYYY'")
 
.ohc_regex(/([^-\w/])((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|&ndash;) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=[^-\w/])/gi, "$1$2@FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2")
Line 771 ⟶ 770:
.ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month @Day, @YYYY(?=\s*[|}])/gi, "$1@Mon @Day, @YYYY")
.ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(?:r?uary|ch|il|[ey]|ust|(?:t?em|o)ber) ([12]?\d|30|31),( (?:19\d|20[01])\d)(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2 $3,$4")
.ohc_regex(/([^-\w\/])@Month @Day, @YYYY([^-\w\/])/gi, '"$1@Mon @Day, @YYYY$2'");
}
 
Line 777 ⟶ 776:
function ohc_abbrev_all_dates(editor) {
editor
.ohc_regex(/([^-\w/])@Day @Month @YYYY(?=[^-\w/])/gi, '"$1@Day @Mon @YYYY'")
.ohc_regex(/([^-\w/])@Month @Day, @YYYY(?=[^-\w/])/gi, '"$1@Mon @Day, @YYYY'");
}
 
Line 803 ⟶ 802:
editor
// Add a tag to the summary box
.replace(/(\{\{use (?:mdy|dmy) dates)(?:\|cs1-dates=\w{1,2}|)(\|[^\}\|]+\}\})/gi, '"$1|cs1-dates=y$2'");
}
 
Line 816 ⟶ 815:
var curryear = currentDate.getFullYear();
var myMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var curryyyymm = myMonths[currmonth] + '" '" + curryear;
 
// step 1: normalize redirect template names to canonical template names 'Use dmy dates' or 'Use mdy dates' according to 'format' argument
editor
// rename redirects 'dmy', 'mdy', 'usedmydates', 'usemdydates' ('usedmydates' and 'usemdydates' are not currently listed as redirects but might be encountered?)
.replace(/\{\{ *(?:use(?:dmy|mdy)dates|dmy|mdy) *([\|\}])/gi, '"{{Use '" + format + '" dates$1'")
 
// rename redirects 'usedmy', 'usemdy', 'use dmy', 'use mdy' to canonical form
.replace(/\{\{ *use *(?:dmy|mdy) *([\|\}])/gi, '"{{Use '" + format + '" dates$1'")
 
// strip leading / trailing whitespace from 'use xxx dates'
.replace(/\{\{ *use (?:dmy|mdy) dates *([\|\}])/gi, '"{{Use '" + format + '" dates$1'");
 
// step 2: look for a canonical template name (the above might not have had anthing to work on) ; if found continue, write new template else
Line 833 ⟶ 832:
var dflagfound = editor.get().search(rxpdd);
if (dflagfound === -1) {
editor.prepend('"{{Use '" + format + '" dates|date='" + curryyyymm + '"}}\r\n'"); // not found so insert new template at top of wikitext
return; // and done
}
Line 839 ⟶ 838:
// step 3: rewrite existing canonical templates; add or refresh |date= to current month year; preserve |cs1-dates= as is
editor
.replace(/(\{\{use (?:dmy|mdy) dates)\| *date *=[^\|]*\| *cs1\-dates *= *([^\|\}]*?) *\}\}/gi, '"$1|date='" + curryyyymm + '"|cs1-dates=$2}}'") // with |date= followed by |cs1-dates=
.replace(/(\{\{use (?:dmy|mdy) dates)\| *cs1\-dates *= *([^\|\}]*?) *\| *date *=[^\}]*\}\}/gi, '"$1|date='" + curryyyymm + '"|cs1-dates=$2}}'") // with |cs1-dates= followed by |date=
.replace(/(\{\{use (?:dmy|mdy) dates)\| *date *=[^\|\}]*\}\}/gi, '"$1|date='" + curryyyymm + '"}}'") // with |date=
.replace(/(\{\{use (?:dmy|mdy) dates)\| *cs1\-dates *= *([^\|\}]*?) \}\}/gi, '"$1|date='" + curryyyymm + '"|cs1-dates=$2}}'") // with |cs1-dates
.replace(/(\{\{use (?:dmy|mdy) dates)\}\}/gi, '"$1|date='" + curryyyymm + '"}}'") // no parameters so add |date=curryyyymm
.replace(/(\{\{[\t_ ]*use[\t_ ]+(?:dmy|mdy)[\t_ ]+dates[^{}]*\}\})([\r\n\t ]*)(\{\{[\t ]*short description[^{}]*\}\})/gi, '"$3$2$1'"); // repositioning "short description" template at the top
}
 
Line 899 ⟶ 898:
 
// retraining redirects containing a date
.replace(/(\[\[)(?:September 3 Society)(\]\]|\|)/gi, '"$1Jiusan Society$2'")
.replace(/(\[\[)(?:June 4th incident)(\]\]|\|)/gi, '"$1Tiananmen Square protests of 1989$2'")
.replace(/(\[\[)(?:5@th? October (?:\(Serbia\)|overthrow))(\]\]|\|)/gi, '"$1Overthrow of Slobodan Milošević$2'")
.replace(/(\[\[)(?:October 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi, '"$1Overthrow of Slobodan Milošević$2'")
 
// protect alternate meanings of 'may' and 'march' (note: not case insensitive)
Line 1,010 ⟶ 1,009:
 
// retraining redirects containing a date
.replace(/(\[\[)(?:September 3 Society)(\]\]|\|)/gi, '"$1Jiusan Society$2'")
.replace(/(\[\[)(?:June 4th incident)(\]\]|\|)/gi, '"$1Tiananmen Square protests of 1989$2'")
.ohc_regex(/(\[\[)(?:5@th? October (?:\(Serbia\)|overthrow))(\]\]|\|)/gi, '"$1Overthrow of Slobodan Milošević$2'")
.ohc_regex(/(\[\[)(?:October 5@th?(?: \(Serbia\)| overthrow|, 2000))(\]\]|\|)/gi, '"$1Overthrow of Slobodan Milošević$2'")
 
// protect alternate meanings of 'may' and 'march' (note: not case insensitive)
Line 1,141 ⟶ 1,140:
editor
.options({ minor: true })
.appendEditSummary('"[[Wikipedia:MOSNUMscript|script]]-assisted date audit and style fixes per [[MOS:NUM]]'")
.clickDiff();
}
Line 1,149 ⟶ 1,148:
editor
.options({ minor: true })
.appendEditSummary('"ymd ref dates'")
.clickDiff();
}
Line 1,157 ⟶ 1,156:
editor
.options({ minor: true })
.appendEditSummary('"expand month names'")
.clickDiff();
}
Line 1,165 ⟶ 1,164:
editor
.options({ minor: true })
.appendEditSummary('"resolved slash dates'")
.clickDiff();
}
Line 1,173 ⟶ 1,172:
editor
.options({ minor: true })
.appendEditSummary('"abbrev month names'")
.clickDiff();
}
Line 1,188 ⟶ 1,187:
/** ------------------------------------------------------------------------ **/
function ohc_body_dates_to_dmy(editor) {
ohc_use_dates_template(editor, '"dmy'");
 
ohc_fix_common_errors(editor);
ohc_fix_dts_template(editor, '"dmy'");
ohc_fix_gr_template(editor, '"dmy'");
ohc_dates_to_dmy(editor);
ohc_remove_leading_zeroes(editor);
Line 1,199 ⟶ 1,198:
 
function ohc_body_dates_to_mdy(editor) {
ohc_use_dates_template(editor, '"mdy'");
ohc_fix_common_errors(editor);
ohc_fix_dts_template(editor, '"mdy'");
ohc_fix_gr_template(editor, '"mdy'");
ohc_dates_to_mdy(editor);
ohc_remove_leading_zeroes(editor);