User:Mxn/CommentsInLocalTime/sandbox.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 144:
"ISO 8601": "YYYY-MM-DDTHH:mm:ss", // xnY-xnm-xnd"T"xnH:xni:xns
},
/**
* Expected format or formats of the timestamps in existing wikitext. If
* very different formats have been used over the course of the wiki’s
* history, specify an array of formats.
*
* This option expects parsing format strings
* <http://momentjs.com/docs/#/parsing/string-format/>.
*/
parseFormat: "H:m, D MMM YYYY",
/**
* Regular expression matching all the timestamps inserted by this MediaWiki
* installation over the years. This regular expression shouldincludes morethe or lessnamed
* capturing groups `hours`, `minutes`, `day`, `month`, `year`, and
* agree with the parseFormat option.
* `timezone`.
*
* Until 2005:
Line 165 ⟶ 156:
* 08:51, 23 November 2015 (UTC)
*/
parseRegExp: /(?<hours>\d\d):(?<minutes>\d\d), (?<day>\d\d?) (?<month>(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\w*) (?<year>\d{4}) \((?<timezone>UTC)\)/,
/**
Line 209 ⟶ 200:
var prefixNode;
while ((prefixNode = iter.nextNode())) {
var then;
var dateNode;
var result = LocalComments.parseRegExp.exec(prefixNode.data);
if (!result) continue;{
// Split out the timestamp into a separate text node.
var suffixNode dateNode = dateNodeprefixNode.splitText(result[0].lengthindex);
// Split out the timestamp into a separate text node.
var dateNodesuffixNode = prefixNodedateNode.splitText(result[0].indexlength);
var suffixNode = dateNode.splitText(result[0].length);
// Determine the represented time.
var components = result.groups;
// Determine the represented time.
var monthIndex = mw.config.get("wgMonthNames").slice(1).indexOf(components.month);
var then = moment.utc(result[0], LocalComments.parseFormat);
if (!then.isValid()) {
// Many Wikipedias started out with English as the default
// localization, so fall back to English.
if (monthIndex === -1) {
then = moment.utc(result[0], "H:m, D MMM YYYY", "en");
monthIndex = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"].indexOf(components.month);
}
if (monthIndex === -1) {
monthIndex = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"].indexOf(components.month);
}
if (monthIndex !== -1) {
then = new Date(Date.utc(components.year, components.monthIndex, components.day, components.hours, components.minutes));
if (!then.isValid()) {
// Many Wikipedias started out with English as the default
// localization, so fall back to English.
var then = moment.utc(result[0], LocalComments.parseFormat"H:m, D MMM YYYY", "en");
}
}
}
Line 238 ⟶ 243:
timeElt.attr("datetime", then.toISOString());
}
if (dateNode) $(dateNode).wrap(timeElt);
}
}