Skip to content

Instantly share code, notes, and snippets.

@muratgozel
Last active November 22, 2017 13:09
Show Gist options
  • Save muratgozel/f0ac3f9a253d221521137e89db8412dd to your computer and use it in GitHub Desktop.
Save muratgozel/f0ac3f9a253d221521137e89db8412dd to your computer and use it in GitHub Desktop.
Convert minutes to hours Number -> HH:HH
function convertMinsToHours(input) {
if (typeof input != 'number') {
return ''
}
const m = input < 0 ? -1 : 1
const k = Math.floor(input*m % 60)
const b = Math.floor(input*m / 60)
return (m==-1 ? '-' : '+') +
(b<10?'0':'')+String(b) + ':' +
(k<10?'0':'')+String(k)
}
/*
* convertMinsToHours(-210) => -03:30
* convertMinsToHours(120) => +02:00
* convertMinsToHours(0) => +00:00
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment