Skip to content

Instantly share code, notes, and snippets.

@gaoxiaoliangz
Created December 11, 2017 03:42
Show Gist options
  • Save gaoxiaoliangz/f86e1fdf470f69c66c5fb307e335edbe to your computer and use it in GitHub Desktop.
Save gaoxiaoliangz/f86e1fdf470f69c66c5fb307e335edbe to your computer and use it in GitHub Desktop.
function toTime(secs) {
const s = secs % 60
const m = (secs - s) / 60
return [(m - (m % 60)) / 60, m % 60, s]
}
function test() {
const tests = [8654, 0, 10, 600, 60, 987678987, 61]
tests.forEach(time => {
const result = toTime(time)
const result2 = result[0] * 60 * 60 + result[1] * 60 + result[2]
console.log(result)
console.log(result2 === time)
})
}
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment