Last active
December 21, 2015 08:28
-
-
Save tylshe/6277860 to your computer and use it in GitHub Desktop.
convertFrames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param frames number | |
* @return string | |
*/ | |
function format (frameNumber) { | |
function convertFrames (frameNumber) { | |
frameNumber = frameNumber + Math.round(frameNumber/1000); | |
var frames = frameNumber % 30; | |
var seconds = (( frameNumber - frames ) / 30) % 60; | |
seconds = (seconds > 0) ? seconds : 0; | |
var minutes = ((frameNumber - seconds * 30 - frames) / 1800 ) % 60; | |
minutes = (minutes > 0) ? minutes : 0; | |
var hours = ((frameNumber - minutes * 60 * 30 - seconds * 30 - frames) / 21600 ) % 12; | |
hours = (hours > 0) ? hours : 0; | |
return [hours, minutes, seconds, frames]; | |
} | |
function convertToString (arr) { | |
for (var i = 0; i < arr.length; i++) { | |
if (arr[i] < 10){ | |
arr[i] = "0" + arr[i]; | |
} | |
} | |
return arr.join(' : '); | |
} | |
return convertToString(convertFrames(frameNumber)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment