3 exports.__esModule = true;
10 * Format seconds as a time string, H:MM:SS or M:SS. Supplying a guide (in seconds)
11 * will force a number of leading zeros to cover the length of the guide.
13 * @param {number} seconds
14 * Number of seconds to be turned into a string
16 * @param {number} guide
17 * Number (in seconds) to model the string after
20 * Time formatted as H:MM:SS or M:SS
22 function formatTime(seconds) {
23 var guide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : seconds;
25 seconds = seconds < 0 ? 0 : seconds;
26 var s = Math.floor(seconds % 60);
27 var m = Math.floor(seconds / 60 % 60);
28 var h = Math.floor(seconds / 3600);
29 var gm = Math.floor(guide / 60 % 60);
30 var gh = Math.floor(guide / 3600);
32 // handle invalid times
33 if (isNaN(seconds) || seconds === Infinity) {
34 // '-' is false for all relational operators (e.g. <, >=) so this setting
35 // will add the minimum number of fields specified by the guide
39 // Check if we need to show hours
40 h = h > 0 || gh > 0 ? h + ':' : '';
42 // If hours are showing, we may need to add a leading zero.
43 // Always show at least one digit of minutes.
44 m = ((h || gm >= 10) && m < 10 ? '0' + m : m) + ':';
46 // Check if leading zero is need for seconds
47 s = s < 10 ? '0' + s : s;
52 exports['default'] = formatTime;