blob: d3869a1cc380cd5f4c25abd7f63ef6cac8af1b0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
function pluralize (n, s) {
return n + " " + (n == 1 ? s : s + "s");
}
function timeInWords (time) {
var str = [];
time /= 1000;
if (time > 86400) {
str.push( pluralize( Math.floor(time / 86400), "day" ) );
}
if (time > 3600) {
str.push( pluralize( Math.floor(time / 3600) % 24, "hour" ) );
}
if (time > 60) {
str.push( pluralize( Math.floor(time / 60) % 60, "minute" ) );
}
var seconds = Math.floor(100 * (time % 60)) / 100;
seconds = (seconds + "").split(".");
if (seconds.length == 1) seconds[1] = "00";
// if (seconds[0].length == 1) seconds[0] = "0" + seconds[0];
if (seconds[1].length == 1) seconds[1] = seconds[1] + "0";
str.push( pluralize( seconds[0] + "." + seconds[1], "second" ) );
return str.join(", ");
}
function timeInMillisecs (time) {
var str = [];
time /= 1000;
if (time > 86400) {
str.push( leading( time / 86400 ) );
}
if (time > 3600) {
str.push( leading( (time / 3600) % 24 ) );
}
if (time > 60) {
str.push( leading( (time / 60) % 60 ) );
} else {
str.push( Math.floor( time / 60 ) );
}
/*
var seconds = Math.floor(10 * (time % 60)) / 10;
seconds = (seconds + "").split(".");
if (seconds.length == 1) seconds[1] = "0";
str.push( leading( time % 60 ) + "." + seconds[1] );
*/
// str.push( leading( time % 60 ) );
var seconds = Math.floor(100 * (time % 60)) / 100;
seconds = (seconds + "").split(".");
if (seconds.length == 1) seconds[1] = "00";
if (seconds[0].length == 1) seconds[0] = "0" + seconds[0];
if (seconds[1].length == 1) seconds[1] = seconds[1] + "0";
str.push( seconds[0] + "." + seconds[1] );
return str.join(":");
}
function leading(num) {
num = Math.floor(num);
return num < 10 ? "0" + num : num;
}
|