Added the Porter Stemmer module to improve searches. This doesn't deal with some...
[yaffs-website] / node_modules / video.js / es5 / utils / format-time.js
1 'use strict';
2
3 exports.__esModule = true;
4 /**
5  * @file format-time.js
6  * @module Format-time
7  */
8
9 /**
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.
12  *
13  * @param {number} seconds
14  *        Number of seconds to be turned into a string
15  *
16  * @param {number} guide
17  *        Number (in seconds) to model the string after
18  *
19  * @return {string}
20  *         Time formatted as H:MM:SS or M:SS
21  */
22 function formatTime(seconds) {
23   var guide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : seconds;
24
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);
31
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
36     h = m = s = '-';
37   }
38
39   // Check if we need to show hours
40   h = h > 0 || gh > 0 ? h + ':' : '';
41
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) + ':';
45
46   // Check if leading zero is need for seconds
47   s = s < 10 ? '0' + s : s;
48
49   return h + m + s;
50 }
51
52 exports['default'] = formatTime;