Index: trunk/extensions/JS2Support/mwEmbed/mwEmbed.js |
— | — | @@ -1854,6 +1854,33 @@ |
1855 | 1855 | // mw.log("warning: trying to get npt time on NaN:" + sec); |
1856 | 1856 | return '0:0:0'; |
1857 | 1857 | } |
| 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 ) { |
1858 | 1885 | var hours = Math.floor( sec / 3600 ); |
1859 | 1886 | var minutes = Math.floor( ( sec / 60 ) % 60 ); |
1860 | 1887 | var seconds = sec % 60; |
— | — | @@ -1863,13 +1890,11 @@ |
1864 | 1891 | } else { |
1865 | 1892 | seconds = Math.round( seconds ); |
1866 | 1893 | } |
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 ]; |
1873 | 1896 | } |
| 1897 | + |
| 1898 | + |
1874 | 1899 | |
1875 | 1900 | /** |
1876 | 1901 | * Take hh:mm:ss,ms or hh:mm:ss.ms input, return the number of seconds |
— | — | @@ -2702,4 +2727,4 @@ |
2703 | 2728 | // (this is needed because packaged loader.js files could refrence jQuery ) |
2704 | 2729 | if( mw.getScriptLoaderPath() && !window.jQuery ) { |
2705 | 2730 | mw.log( 'Error: jQuery is required for mwEmbed, please update your script-loader request' ); |
2706 | | -} |
\ No newline at end of file |
| 2731 | +} |