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

Content deleted Content added
protect Canadian federal by-election template
partial alignment to test script
Line 121:
ohc_regex(/\[\[@DD@th?(?:\s|_| )@Month\]\]/gi, "@Day @LMonth");
ohc_regex(/\[\[@Month(?:\s|_| )@DD@th?\]\]@th?/gi, "@LMonth @Day"); //consolidated regex with flexible removal of ordinal simple date
ohc_regex(/\[\[@Day @Month\]\]/gi, "@Day @MonthLMonth");
ohc_regex(/\[\[@Month @YYYY\]\]/gi, "@MonthLMonth @YYYY");
ohc_regex(/\[\[@YYYY\]\]/gi, "@YYYY");
 
Line 134:
 
// remove nowrap template from dm and md dates
ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@DD(?:[ _]| )@Month)( @yyyy|)\}\}/gi, '$1@DD @MonthLMonth$2');
ohc_regex(/(date[ ]*=[ ]*)\{\{(?:j|no ?(?:break|wrap))\|(?:@Month(?:[ _]| )@DD)( @yyyy|)\}\}/gi, '$1@MonthLMonth @DD$2');
//delink yyyy-mm-dd dates
Line 150:
 
//delink single dm or 'dth the m'
ohc_regex(/(?:the\s)?\[\[@Day@th?[\s_](?:of[\s_])?@Month\]\]/gi, "@Day @LMonth");
//delink single md or 'm the dth'
ohc_regex(/\[\[@Month[\s_](?:the[\s_])?@Day@th?\]\](?=\W)/gi, "@LMonth @Day");
 
//Month+day_number "[[March 7]]th" -> "March 7"
Line 176:
regex(/\[\[(?: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');
regex(/\[\[(\d{1,2}(?:st|[nr]d|th)[\s\-_])(centur(?:y|ies))(\s(?:AD|BC|CE|BCE)|)\]\]/gi, '$1$2$3');
regexohc_regex(/\[\[\d{1,2}(?:st|[nr]d|@th)[\s\-_]centur(?:y|ies)(?:\s(?:AD|BC|CE|BCE)|)\|([^\]]{1,30})\]\]/gi, '$1');
 
// months
ohc_regex(/\[\[@Month\]\]/gi, "@MonthLMonth");
ohc_regex(/\[\[@FullMonth\|([^\]]{1,30})\]\]/gi, "$1");
 
Line 196:
//month+year
//Identify surprise or 'Easter egg' diversions linking month+years to year articles. Turn them into month+year links to be dealt with below
ohc_regex(/\[\[@yyyy in[^|\]]+\|@Day @Month @YYYY\]\]/gi, "@Day @MonthLMonth @YYYY");
ohc_regex(/\[\[@yyyy in[^|\]]+\|@Month @Day,? @YYYY\]\]/gi, "@MonthLMonth @Day, @YYYY");
ohc_regex(/\[\[@yyyy#[^|\]]+\|(@month\s|)(@yyyy)\]\]/gi, "$1$2");
ohc_regex(/\[\[@yyyy#[^|\]]+\|(@month|@yyyy)\]\]/gi, "$1");
Line 214:
//Identify surprise or 'Easter egg' diversions linking months to year or "year in" articles.
ohc_regex(/\[\[\d{1,4}#[^|\]]+\|@Month\]\]/gi, "@LMonth");
ohc_regex(/@DD\s@Month,?\s?\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi, '@DD @LMonth @Year');
ohc_regex(/@Month\s@DD,?\s?\[\[@yyyy \w[^|\]]{3,12}\|@Year\]\]/gi, '@LMonth @DD, @Year');
 
// month and day piped
ohc_regex(/@YYYY-\[\[@month[\s_]@day\|@MM-@DD\]\]/gi, "@YYYY-@MM-@DD");
ohc_regex(/\[\[@month[\s_]@day\|([^\]]{1,30})\]\]/gi, "$1");
ohc_regex(/\[\[@day(?:\s|_|@th )(?:of[\s_]|)?@month\|([^\]]{1,30})\]\]/gi, "$1");
Line 261 ⟶ 260:
 
// remove parasitic metadata - days of the week/descriptives
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)(?:[^|}\d]*|)@Day\s+@Month\s+@YYYY((?:[a-z]\b|)\s?)[^|<}]*(?=[\s\n]*[<|}])/gi, "$1@Day @Month @YYYY$2"); //rem negate "<", "hyphens" "dashes" 26/6/2020
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)[^|}]*@Month\s+@Day,\s+@YYYY((?:[a-z]\b|)\s?)[^|<}]*(?=[\s\n]*[<|}])/gi, "$1@Month @Day, @YYYY$2"); //rem negate "<", "hyphens" "dashes" 26/6/2020
// ohc_regex(/(\|\s*date\s*=\s*)(?:[^|}–<]*\D|)@Day\s+@Month\s+@YYYY ?– ?@Day\s+@Month\s+@YYYY[^|}–<]*(?=[\s\n]*[<|}])/gi, "$1@Day1 @Mon1 @Year1 – @Day2 @Mon2 @Year2");
// ohc_regex(/(\|\s*date\s*=\s*)[^|}–<]*@Month\s+@Day,\s+@YYYY ?– ?@Month @Day, @YYYY[^|}–<]*(?=[\s\n]*[<|}])/gi, "$1@Mon1 @Day1, @Year1 – @@Mon2 Day2, @Year2");
Line 341 ⟶ 340:
//zap redundant {{date}}, {{accessdate}} {{retrieved}}, {{monthname}} and {{#dateformat}}
// regex(/({{(?:end|start)[-–]date)\|df=y(?:es|)/gi, "$1"); //rem deprecated parameter - disabled: doesn't work here, so ejected to the formatting script
ohc_regex(/{{#formatdate:@YYYY-@MM-@DD(?:[^\}]*)}}/gi, "@Day @Month @YYYY");
regex(/{{#formatdate:([^}]+)}}/gi, "$1");
regex(/\{\{#dateformat:([^}\|]+)(?:\|dmy|\|mdy)?\}\}/gi, '$1');
Line 373:
regex(/(\(20)([01])(7)[-–]([8-9]\))/gi, '$1$2$3–$2$4');
regex(/(\(20)([01])(8)[-–](9\))/gi, '$1$2$3–$2$4');
 
//remove unlinked ordinal date formats
// ohc_regex(/(\Wthe |)@DD@th?(?:\sof|)\s@Month,? @YYYY (concert|edition|show|performance)/gi, '$1$2 of @Day @LMonth @YYYY');
// ohc_regex(/(\Wthe |)@Month @DD@th?,?\s@YYYY (concert|edition|show|performance)/gi, '$1$2 of @LMonth @Day, @YYYY');
// ohc_regex(/(\Wthe |)@DD@th?(?:\sof|)\s@Month (concert|edition|show|performance)/gi, '$1$2 of @Day @LMonth');
// ohc_regex(/(\Wthe |)@Month @DD@th? (concert|edition|show|performance)/gi, '$1$2 of @LMonth @Day');
 
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');
Line 496 ⟶ 490:
ohc_regex(/(\D\W)@Month(\s|&nbsp;)@DD@th?(?:(?:\s*|&nbsp;|)[-–](?:\s*|&nbsp;|))@DD@th?(?=\W\D)/gi, "$1@LMonth1$2@Day1–@Day2");
ohc_regex(/(\D\W)@DD@th?(?:(?:\s*|&nbsp;|)[-–](?:\s*|&nbsp;|))@DD@th?(\s|&nbsp;)@Month(?=\W\D)/gi, "$1@Day1–@Day2$2@LMonth1");
 
//reformat dmy-dmy and mdy-mdy (birth-death ranges)
// ohc_regex(/(\D\W)@DD\s@Month,? @Year(&nbsp;|\s)(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@DD\s@Month,? @Year(?=\D\W)/gi, "$1@Day1 @LMonth1 @Year1$2– @Day2 @LMonth2 @Year2");
// ohc_regex(/(\D\W)@Month\s@DD,? @Year(&nbsp;|\s)(?:(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@Month\s@DD,? @Year(?=\D\W)/gi, "$1@LMonth1 @Day1, @Year1$2– @LMonth2 @Day2, @Year2");
// ohc_regex(/(\D\W)@DD\s@Month,? @Year(?:,?(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@DD\s@Month,? @Year(?=\D\W)/gi, "$1@Day1 @LMonth1 @Year1 – @Day2 @LMonth2 @Year2");
// ohc_regex(/(\D\W)@Month\s@DD,? @Year(?:,?(?:[-–—]|&[mn]dash;)(?:&nbsp;|\s)?)@Month\s@DD,? @Year(?=\D\W)/gi, "$1@LMonth1 @Day1, @Year1 – @LMonth2 @Day2, @Year2");
 
//nbsp in publication archive & access dates
// ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*@dd)&nbsp;(@month)/gi, '$1 $2');
// ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month&nbsp;@DD(, @yyyy|)(?=[ ]*[|}])/gi, '$1@Month $2');
 
// spaces and commas between month and year (again)
Line 694 ⟶ 678:
 
//add comma where missing
ohc_regex(/(\D\W)@Month\s@Day,?\s@YYYY,?(?=\s@yyyy\W\Dw)/gi, "$1@LMonth @Day, @YYYY,");
//rem superfluous comma where applicable
ohc_regex(/(\D[^\w\/])@Month\s@ZD,,(?=\W\D|\b)/gi, "$1@LMonth @Day,");
Line 728 ⟶ 712:
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)@Month,?( (?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month,? @YYYY(?=\s*[|}])/gi, "$1@FullMonth1$2 – @FullMonth2 @YYYY");
ohc_regex(/(\|\s*(?:publication|archive|access|air|)-?date\s*=\s*)((?:19|20)\d\d) ?(?:-|–|&ndash;) ?@Month @YYYY(?=\s*[|}])/gi, "$1@$2 – @FullMonth @YYYY");
//commenting out 3 lines- unexplained error 30 May 2014
// ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@FullMonth @YYYY");
// ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Day @Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@Day @FullMonth @YYYY");
// ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))@Month @Day, @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1@FullMonth @Day, @YYYY");
 
ohc_regex(/(<ref[^>]*>(?:[^<]+?[\s\(]|))((?:[01-2]?\d|30|31) |)@Month @YYYY ?(?:-|–|&ndash;) ?((?:[01-3]?\d|30|31) |)@Month @YYYY(?=(?:[^-\w\/%,<][^<]*?|)<\/ref>)/gi, "$1$2@FullMonth1 @YYYY1 – $3@FullMonth2 @YYYY2");
Line 908 ⟶ 888:
regex(/([\s\S])(23rd March 1931: Shaheed)([\s\S])/gi, protect_function);
regex(/([\s\S])(Long March [1-7])([\s\S])/gi, protect_function);
regex(/([\s\S])(National September 11 Memorial & Museum)([\s\S])/gi, protect_function);
regex(/([\s\S])(Queen Elizabeth II September 11th Garden)([\s\S])/gi, protect_function);
regex(/([\s\S])(Bombay March 12)([\s\S])/gi, protect_function);
regex(/([\s\S])(movement 2 June)([\s\S])/gi, protect_function);
Line 914 ⟶ 896:
regex(/([\s\S])(4th\sof August regime)([\s\S])/gi, protect_function);
regex(/([\s\S])(19th\sof April movement)([\s\S])/gi, protect_function);
regex(/([\s\S])(June 4th (?:incident|museum))([\s\S])/gi, protect_function);
regex(/([\s\S])(The Battle Of Marston Moor \(July 2nd,? 1644\))([\s\S])/gi, protect_function);
regex(/([\s\S])(Night of January 16th)([\s\S])/gi, protect_function);
Line 949 ⟶ 931:
ohc_regex(/(Bootmoon Series: [\w ]*[-–] @fullmonth)( @day, @YYYY)(.)/gi, protect_function);
 
// expressions and grammatical strings including modal "may"
regex(/(\W)((?:\d{1,3}) may)((?: have(?: \w+|)|) be)/g, protect_function);
regex(/(\W)((?:\d{3}|3[2-9]|[4-9]\d)\/\d dec(?:l\.?|))(\W)/gi, protect_function);
regex(/(\W)((?:\d{2,3})\/\d dec(?:l\.?|))( \(\d\d? overs)/gi, protect_function);
Line 1,186 ⟶ 1,170:
 
/** ------------------------------------------------------------------------ **/
/// DRIVER FUNCTIONS
 
function ohc_body_dates_to_dmy()
{
Line 1,212 ⟶ 1,194:
 
/** ------------------------------------------------------------------------ **/
/// DRIVER FUNCTIONS
 
function ohc_all_to_dmy_driver(e)
{
Line 1,323 ⟶ 1,303:
ohc_delink_year_in_X();
}
 
//function ohc_Bigendian_ref_dates_driver(e)
//{
// e.preventDefault();
// Add a tag to the summary box
// ohc_Bigendian_ref_dates();
// ohc_bigendien_edit_summary();
//}
 
function ohc_expand_ref_dates_driver(e) {