User:Bosco/Unsigned helper.js: Difference between revisions

From Test Wiki
Content deleted Content added
add advertisement to the edit summary
createTimestampWikitext: move timestamp formatting into wikitext = one usage of `const months` fewer
Line 342: Line 342:
return 'Unsigned';
return 'Unsigned';
}
}
}
function createTimestampWikitext(timestamp) {
// https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##time_format_like_in_signatures
return '{{' + `subst:#time:H:i, j xg Y "(UTC)"|${timestamp}}}`;
}
}


function makeUnsignedTemplate(user, timestamp, template) {
function makeUnsignedTemplate(user, timestamp, template) {
const ts = new Date(timestamp);
const formattedTimestamp = createTimestampWikitext(timestamp);
let h = ts.getUTCHours();
if (h < 10) {
h = '0' + h;
}
let m = ts.getUTCMinutes();
if (m < 10) {
m = '0' + m;
}
const formattedTimestamp = `${h}:${m}, ${ts.getUTCDate()} ${months[ts.getUTCMonth()]} ${ts.getUTCFullYear()} (UTC)`;
return '{{subst:' + template + '|' + user + '|' + formattedTimestamp + '}}';
return '{{subst:' + template + '|' + user + '|' + formattedTimestamp + '}}';
}
}