r66451 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66450‎ | r66451 | r66452 >
Date:22:35, 14 May 2010
Author:neilk
Status:deferred
Tags:
Comment:
function to get time components before formatting
Modified paths:
  • /trunk/extensions/JS2Support/mwEmbed/mwEmbed.js (modified) (history)

Diff [purge]

Index: trunk/extensions/JS2Support/mwEmbed/mwEmbed.js
@@ -1854,6 +1854,33 @@
18551855 // mw.log("warning: trying to get npt time on NaN:" + sec);
18561856 return '0:0:0';
18571857 }
 1858+
 1859+ var tm = mw.seconds2tm( sec, show_ms );
 1860+ var seconds = tm[0];
 1861+ var minutes = tm[1];
 1862+ var hours = tm[2];
 1863+
 1864+ if ( seconds < 10 ) {
 1865+ seconds = '0' + seconds;
 1866+ }
 1867+
 1868+ if ( minutes < 10 ) {
 1869+ minutes = '0' + minutes;
 1870+ }
 1871+
 1872+ return hours + ":" + minutes + ":" + seconds;
 1873+ }
 1874+
 1875+ /**
 1876+ * Given a float number of seconds, returns an array of [seconds, minutes, hours]
 1877+ * For the weak similarity to struct tm in C, it's called seconds2tm
 1878+ *
 1879+ * @param {Float} sec Seconds
 1880+ * @param {Boolean} show_ms If milliseconds should be displayed.
 1881+ * @return {Array} of [ Integer seconds, Integer minutes, Integer hours ] (seconds is float if show_ms is true).
 1882+ * @type {Array}
 1883+ */
 1884+ mw.seconds2tm = function( sec, show_ms ) {
18581885 var hours = Math.floor( sec / 3600 );
18591886 var minutes = Math.floor( ( sec / 60 ) % 60 );
18601887 var seconds = sec % 60;
@@ -1863,13 +1890,11 @@
18641891 } else {
18651892 seconds = Math.round( seconds );
18661893 }
1867 - if ( seconds < 10 )
1868 - seconds = '0' + seconds;
1869 - if ( minutes < 10 )
1870 - minutes = '0' + minutes;
1871 -
1872 - return hours + ":" + minutes + ":" + seconds;
 1894+
 1895+ return [ seconds, minutes, hours ];
18731896 }
 1897+
 1898+
18741899
18751900 /**
18761901 * Take hh:mm:ss,ms or hh:mm:ss.ms input, return the number of seconds
@@ -2702,4 +2727,4 @@
27032728 // (this is needed because packaged loader.js files could refrence jQuery )
27042729 if( mw.getScriptLoaderPath() && !window.jQuery ) {
27052730 mw.log( 'Error: jQuery is required for mwEmbed, please update your script-loader request' );
2706 -}
\ No newline at end of file
 2731+}

Status & tagging log