Last active
November 22, 2017 13:09
-
-
Save muratgozel/f0ac3f9a253d221521137e89db8412dd to your computer and use it in GitHub Desktop.
Convert minutes to hours Number -> HH:HH
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
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