Jump to content

User:Gimmetrow/dates.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre><code>
//

function mosdate() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value

   //MOSDATE remove th in dates followed by -th, others
    //.replace(/([^\[])(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)(th|st|nd|rd)/gi, '$1[[$2 $3]]')
    .replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)(th|st|nd|rd)/gi, '$1 $2')
    .replace(/\[\[(January|February|March|April|May|June|July|August|September|October|November|December)\s(\d\d?)\]\](<sup>)?(th|st|nd|rd)(<\/sup>)?/gi, '[[$1 $2]]') 
    .replace(/(\D\d\d?)(<sup>)?(th|st|nd|rd)(<\/sup>)?\s(January|February|March|April|May|June|July|August|September|October|November|December)/gi, '$1 $5')
    .replace(/\s(\d{3}0)'s(\W)/gi, ' $1s$2')
    .replace(/the\s(January|February|March|April|May|June|July|August|September|October|November|December)\sof\s(\d{4})/gi, '$1 $2')
    .replace(/(January|February|March|April|May|June|July|August|September|October|November|December)\sof\s(\d{4})/gi, '$1 $2')
    .replace(/the\s(\d\d?)(th|st|nd|rd)\sof\s(January|February|March|April|May|June|July|August|September|October|November|December)/gi, '$3 $1')
    .replace(/(\d\dth\s)Century/g, '$1century')
    .replace(/20th century([ -])(Fox|Pictures|Limited|Film|Frog)/g, '20th Century$1$2');
}

function accessISO() {
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (January|Jan\.|Jan),? *([1-2][0-9][0-9][0-9])/g, "$1$4-01-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(January|Jan\.|Jan) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-01-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (February|Feb\.|Feb),? *([1-2][0-9][0-9][0-9])/g, "$1$4-02-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(February|Feb\.|Feb) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-02-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (March|Mar\.|Mar),? *([1-2][0-9][0-9][0-9])/g, "$1$4-03-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(March|Mar\.|Mar) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-03-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (April|Apr\.|Apr),? *([1-2][0-9][0-9][0-9])/g, "$1$4-04-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(April|Apr\.|Aor) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-04-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (May|May\.),? *([1-2][0-9][0-9][0-9])/g, "$1$4-05-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(May|May\.) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-05-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (June|Jun\.|Jun),? *([1-2][0-9][0-9][0-9])/g, "$1$4-06-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(June|Jun\.|Jun) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-06-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (July|Jul\.|Jul),? *([1-2][0-9][0-9][0-9])/g, "$1$4-07-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(July|Jul\.|Jul) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-07-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (August|Aug\.|Aug),? *([1-2][0-9][0-9][0-9])/g, "$1$4-08-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(August|Aug\.|Aug) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-08-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (September|Sept\.|Sept|Sep\.|Sep),? *([1-2][0-9][0-9][0-9])/g, "$1$4-09-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(September|Sept\.|Sept|Sep\.|Sep) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-09-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (October|Oct\.|Oct),? *([1-2][0-9][0-9][0-9])/g, "$1$4-10-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(October|Oct\.|Oct) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-10-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (November|Nov\.|Nov),? *([1-2][0-9][0-9][0-9])/g, "$1$4-11-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(November|Nov\.|Nov) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-11-$3")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)([0-3][0-9]|[0-9]) (December|Dec\.|Dec),? *([1-2][0-9][0-9][0-9])/g, "$1$4-12-$2")
   .replace(/(\|[ ]*accessdate[ ]*=[ ]*)(December|Dec\.|Dec) ([0-3][0-9]|[0-9]),? *([1-2][0-9][0-9][0-9])/g, "$1$4-12-$3");
}

function ISOtodmy() {
   var txt = document.editform.wpTextbox1;

   txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])\]\]/g, "$1");
   txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9])\]\]-\[\[([0-1][0-9]-[0-3][0-9])\]\]/g, "$1-$2");

   //txt.value = txt.value.replace(/accesse?date[ ]*=[ ]*/gi, "QQQaccessdateQQQ"); // avoid, but fix a quirk
   //txt.value = txt.value.replace(/accessed[ ]+/g, "QQQaccessedQQQ"); // avoid
   //txt.value = txt.value.replace(/Accessed[ ]+/g, "QQQAccessedQQQ"); // avoid

   txt.value = txt.value
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-01-0([1-9])([^0-9a-zA-Z])/g, "$1$3 January $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-02-0([1-9])([^0-9a-zA-Z])/g, "$1$3 February $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-03-0([1-9])([^0-9a-zA-Z])/g, "$1$3 March $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-04-0([1-9])([^0-9a-zA-Z])/g, "$1$3 April $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-05-0([1-9])([^0-9a-zA-Z])/g, "$1$3 May $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-06-0([1-9])([^0-9a-zA-Z])/g, "$1$3 June $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-07-0([1-9])([^0-9a-zA-Z])/g, "$1$3 July $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-08-0([1-9])([^0-9a-zA-Z])/g, "$1$3 August $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-09-0([1-9])([^0-9a-zA-Z])/g, "$1$3 September $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-10-0([1-9])([^0-9a-zA-Z])/g, "$1$3 October $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-11-0([1-9])([^0-9a-zA-Z])/g, "$1$3 November $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-12-0([1-9])([^0-9a-zA-Z])/g, "$1$3 December $2$4");

   txt.value = txt.value
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-01-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 January $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-02-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 February $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-03-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 March $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-04-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 April $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-05-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 May $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-06-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 June $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-07-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 July $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-08-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 August $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-09-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 September $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-10-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 October $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-11-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 November $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-12-([1-3][0-9])([^0-9a-zA-Z])/g, "$1$3 December $2$4");

   //txt.value = txt.value.replace(/QQQaccessdateQQQ/g, "accessdate=");
   //txt.value = txt.value.replace(/QQQaccessedQQQ/g, "accessed ");
   //txt.value = txt.value.replace(/QQQAccessedQQQ/g, "Accessed ");
}

function ISOtomdy() {
   var txt = document.editform.wpTextbox1;

   txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])\]\]/g, "$1");
   txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9])\]\]-\[\[([0-1][0-9]-[0-3][0-9])\]\]/g, "$1-$2");

   //txt.value = txt.value.replace(/accesse?date[ ]*=[ ]*/gi, "QQQaccessdateQQQ"); // avoid, but fix a quirk
   //txt.value = txt.value.replace(/accessed[ ]+/g, "QQQaccessedQQQ"); // avoid
   //txt.value = txt.value.replace(/Accessed[ ]+/g, "QQQAccessedQQQ"); // avoid

   txt.value = txt.value
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-01-0([1-9])([^0-9a-zA-Z])/g, "$1 January $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-02-0([1-9])([^0-9a-zA-Z])/g, "$1February $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-03-0([1-9])([^0-9a-zA-Z])/g, "$1March $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-04-0([1-9])([^0-9a-zA-Z])/g, "$1April $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-05-0([1-9])([^0-9a-zA-Z])/g, "$1May $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-06-0([1-9])([^0-9a-zA-Z])/g, "$1June $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-07-0([1-9])([^0-9a-zA-Z])/g, "$1July $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-08-0([1-9])([^0-9a-zA-Z])/g, "$1August $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-09-0([1-9])([^0-9a-zA-Z])/g, "$1September $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-10-0([1-9])([^0-9a-zA-Z])/g, "$1October $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-11-0([1-9])([^0-9a-zA-Z])/g, "$1November $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-12-0([1-9])([^0-9a-zA-Z])/g, "$1December $3, $2$4");

   txt.value = txt.value
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-01-([1-3][0-9])([^0-9a-zA-Z])/g, "$1January $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-02-([1-3][0-9])([^0-9a-zA-Z])/g, "$1February $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-03-([1-3][0-9])([^0-9a-zA-Z])/g, "$1March $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-04-([1-3][0-9])([^0-9a-zA-Z])/g, "$1April $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-05-([1-3][0-9])([^0-9a-zA-Z])/g, "$1May $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-06-([1-3][0-9])([^0-9a-zA-Z])/g, "$1June $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-07-([1-3][0-9])([^0-9a-zA-Z])/g, "$1July $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-08-([1-3][0-9])([^0-9a-zA-Z])/g, "$1August $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-09-([1-3][0-9])([^0-9a-zA-Z])/g, "$1September $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-10-([1-3][0-9])([^0-9a-zA-Z])/g, "$1October $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-11-([1-3][0-9])([^0-9a-zA-Z])/g, "$1November $3, $2$4")
   .replace(/(\|[ ]*date[ ]*=[ ]*)([1-2][0-9][0-9][0-9])-12-([1-3][0-9])([^0-9a-zA-Z])/g, "$1December $3, $2$4");

   //txt.value = txt.value.replace(/QQQaccessdateQQQ/g, "accessdate=");
   //txt.value = txt.value.replace(/QQQaccessedQQQ/g, "accessed ");
   //txt.value = txt.value.replace(/QQQAccessedQQQ/g, "Accessed ");
}

function riskyISO() {
   var txt = document.editform.wpTextbox1;

   txt.value = txt.value.replace(/\[\[([1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9])\]\]/g, "$1");

   txt.value = txt.value
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-01-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 January $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-02-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 February $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-03-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 March $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-04-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 April $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-05-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 May $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-06-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 June $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-07-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 July $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-08-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 August $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-09-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 September $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-10-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 October $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-11-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 November $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-12-0([1-9])([^0-9a-zA-Z-])/g, "$1$3 December $2$4");

   txt.value = txt.value
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-01-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 January $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-02-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 February $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-03-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 March $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-04-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 April $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-05-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 May $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-06-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 June $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-07-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 July $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-08-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 August $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-09-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 September $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-10-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 October $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-11-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 November $2$4")
   .replace(/([^0-9a-zA-Z-])([1-2][0-9][0-9][0-9])-12-([1-3][0-9])([^0-9a-zA-Z-])/g, "$1$3 December $2$4");

   //txt.value = txt.value.replace(/QQQaccessdateQQQ/g, "accessdate=");
   //txt.value = txt.value.replace(/QQQaccessedQQQ/g, "accessed ");
   //txt.value = txt.value.replace(/QQQAccessedQQQ/g, "Accessed ");
}

function yearinX() {
   var monthyear = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December),? *([0-9][0-9][0-9][0-9])\\]\\]", "g");
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(/\[\[[1-2][0-9][0-9][0-9] in [A-Za-z ]+\|([1-2][0-9][0-9][0-9])\]\]/g, "[[$1]]");
   txt.value = txt.value.replace(/([^,\]] |[^,\] ])\[\[([1-2][0-9][0-9][0-9])\]\]/g, "$1$2");
   txt.value = txt.value.replace(monthyear, "$1 $2");
}

function dayMonth(option) {
   var daymonth = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g");
   var monthday = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g");
   var daymonth2 = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\]", "g");
   var monthday2 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\]", "g");

   var txt = document.editform.wpTextbox1;
   if (option == 1) {
      // dd Month
      txt.value = txt.value.replace(monthday , "[[$2 $1]] [[$3]]");
      txt.value = txt.value.replace(daymonth , "[[$1 $2]] [[$3]]");
      txt.value = txt.value.replace(monthday2, "[[$2 $1]]");
      txt.value = txt.value.replace(daymonth2, "[[$1 $2]]");
   } else {
      // Month dd
      txt.value = txt.value.replace(monthday , "[[$1 $2]], [[$3]]");
      txt.value = txt.value.replace(daymonth , "[[$2 $1]], [[$3]]");
      txt.value = txt.value.replace(monthday2, "[[$1 $2]]");
      txt.value = txt.value.replace(daymonth2, "[[$2 $1]]");
   }
}

function addDLinks() {
   var daymonth = new RegExp("([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December),? *([0-9][0-9][0-9][0-9])", "g");
   var monthday = new RegExp("(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9]),? *([0-9][0-9][0-9][0-9])", "g");
   var daymonth2 = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *([0-9][0-9][0-9][0-9])", "g");
   var monthday2 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\],? *([0-9][0-9][0-9][0-9])", "g");
   var daymonth3 = new RegExp("([^0-9\[])([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)([^0-9\\]])", "g");
   var monthday3 = new RegExp("([^0-9\[])(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])([^0-9\\]])", "g");
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(monthday, "[[$1 $2]], [[$3]]");
   txt.value = txt.value.replace(daymonth, "[[$1 $2]] [[$3]]");
   txt.value = txt.value.replace(monthday2, "[[$1 $2]], [[$3]]");
   txt.value = txt.value.replace(daymonth2, "[[$1 $2]] [[$3]]");
   txt.value = txt.value.replace(monthday3, "$1[[$2 $3]]$4");
   txt.value = txt.value.replace(daymonth3, "$1[[$2 $3]]$4");
}

function remDLinks() {
   var daymonth = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g");
   var monthday = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\],? *\\[\\[([0-9][0-9][0-9][0-9])\\]\\]", "g");
   var daymonth3 = new RegExp("\\[\\[([0-3][0-9]|[0-9]) (January|February|March|April|May|June|July|August|September|October|November|December)\\]\\]", "g");
   var monthday3 = new RegExp("\\[\\[(January|February|March|April|May|June|July|August|September|October|November|December) ([0-3][0-9]|[0-9])\\]\\]", "g");
   var txt = document.editform.wpTextbox1;
   txt.value = txt.value.replace(monthday, "$1 $2, $3");
   txt.value = txt.value.replace(daymonth, "$1 $2 $3");
   txt.value = txt.value.replace(monthday3, "$1 $2");
   txt.value = txt.value.replace(daymonth3, "$1 $2");
}

addOnloadHook(function () {
    if(document.forms.editform) {
        mw.util.addPortletLink('p-tb', 'javascript:mosdate()'  , 'Format mosdate   ', 't-mosdate',  'Regexp mosdate', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ISOtodmy()' , 'Format ISO->dmy  ', 't-ISOtodmy', 'Regexp ISOtodmy', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:ISOtomdy()' , 'Format ISO->mdy  ', 't-ISOtomdy', 'Regexp ISOtomdy', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:accessISO()', 'Format acd->ISO  ', 't-acdtoISO', 'Regexp acdtoISO', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:riskyISO()' , 'Format riskyISO  ', 't-riskyISO', 'Regexp riskyISO', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:yearinX()'  , 'Format -year in X', 't-yearinX',  'Regexp yearinX', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:addDLinks()', 'Format +datelinks', 't-addlinks', 'Regexp links', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:dayMonth(1)', '=Format \[\[DMY]]', 't-daymonth', 'Regexp day month', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:dayMonth(2)', '=Format \[\[MDY]]', 't-monthday', 'Regexp month day', '', '');
        mw.util.addPortletLink('p-tb', 'javascript:remDLinks()', 'Format -datelinks', 't-remlinks', 'Regexp links', '', '');
    }
});
//</code></pre>