User:BDavis (WMF)/Scripts/zonestamp-moment.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * Display times wrapped in [[Template:Zonestamp]] as local times using moment.
 * 
 * License: CC0
 */
mw.loader.using( "moment", mw.hook( "wikipage.content" ).add( function () {
	var formats = {
		mdy: "HH:mm, MMMM D, YYYY",
		dmy: "HH:mm, D MMMM YYYY",
		ymd: "HH:mm, YYYY MMMM D",
		"ISO 8601": "YYYY-MM-DDTHH:mm"
	};
	var fmt = formats[ mw.user.options.values.date ] || "LLL";
	document.querySelectorAll( "time.zonestamp, time.tpl-zonestamp" ).forEach( function ( e ) {
		e.textContent = moment( e.dateTime, moment.ISO_8601 ).format( fmt );
	});
}));