Skip to content

Commit

Permalink
just for the sake of it
Browse files Browse the repository at this point in the history
  • Loading branch information
FallBackITA27 committed Jun 1, 2024
1 parent 7ceb5a6 commit 498b7f3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions generic/timeUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function formatMsToTime(i32) {
let mins = Math.trunc(i32 / 60000);
i32 %= 60000;
let sec = Math.trunc(i32 / 1000);
i32 %= 1000;
let ret = `${mins.toString().padStart(2, "0")}:${sec.toString().padStart(2, "0")}.${Math.trunc(i32).toString().padStart(3, "0")}`;
return ret;
}

function timeToMs(timeStr) {
let split = timeStr.split("'");
let mins = parseInt(split[0]);
let split2 = split[1].split("\"");
let secs = parseInt(split2[0]);
let ms = parseInt(split2[1]);
return mins * 60000 + secs * 1000 + ms
}

function timeToMsColons(timeStr) {
let split = timeStr.split(":");
let mins = parseInt(split[0]);
let split2 = split[1].split(".");
let secs = parseInt(split2[0]);
let ms = parseInt(split2[1]);
return mins * 60000 + secs * 1000 + ms
}

function sumTimesColon(timeArray) {
return formatMsToTime(timeArray.reduce((a,b)=>a+timeToMsColons(b),0));
}

function timeDiffColon(time1, time2) {
return formatMsToTime(timeToMsColons(time2)-timeToMsColons(time1));
}

0 comments on commit 498b7f3

Please sign in to comment.