Skip to content

Instantly share code, notes, and snippets.

@ktokot
Last active July 21, 2020 10:45
Show Gist options
  • Save ktokot/158a4c29e255f1358dff7e902d258fcc to your computer and use it in GitHub Desktop.
Save ktokot/158a4c29e255f1358dff7e902d258fcc to your computer and use it in GitHub Desktop.
c.1.3.1
console.info(addTime(11, 2, 118));
// 13:00
console.info(addTime(23, 59, 31));
// 00:30
function minutestoTime(m) {
let result = "";
let hh = (m / 60) % 24 - (((m / 60) % 24) % 1);
let mm = m - (m/60 - m/60%1)*60 ;
if (hh < 10) {
hh = pad(hh, 2);
}
if (hh == 0) {
hh = '0';
}
if (mm < 10) {
mm = pad(mm, 2);
}
return (result = hh + ":" + mm);
}
function pad(num, size) {
var s = "0" + num;
return s.substr(s.length - size);
}
function addTime(h, m, i) {
var a = h * 60 + m + i;
var result=minutestoTime(a);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment