author | ymh <ymh.work@gmail.com> |
Thu, 22 Jan 2015 12:12:33 +0100 | |
changeset 119 | e6605fecb175 |
parent 105 | 25ac8802c189 |
child 122 | 3b11017a76a4 |
permissions | -rw-r--r-- |
99 | 1 |
/** |
2 |
* js/utils.js |
|
3 |
* |
|
4 |
* basic tools |
|
5 |
* |
|
6 |
*/ |
|
7 |
||
8 |
'use strict'; |
|
9 |
||
105
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
10 |
function formatTime (ts) { |
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
11 |
var hours = Math.floor( (ts/1000) / 3600 ) % 24; |
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
12 |
var minutes = Math.floor( (ts/1000) / 60 ) % 60; |
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
13 |
var seconds = Math.floor( (ts/1000) % 60); |
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
14 |
return ((hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds)); |
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
15 |
} |
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
16 |
|
119 | 17 |
function colorToHex(c) { |
18 |
var m = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(c); |
|
19 |
return m ? '#' + (1 << 24 | m[1] << 16 | m[2] << 8 | m[3]).toString(16).substr(1) : c; |
|
20 |
} |
|
21 |
||
22 |
||
105
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
23 |
|
25ac8802c189
Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents:
99
diff
changeset
|
24 |
module.exports = { |
119 | 25 |
formatTime: formatTime, |
26 |
colorToHex: colorToHex |
|
99 | 27 |
}; |