aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMango0x45 <thomasvoss@live.com> 2021-02-03 18:12:48 +0100
committerMango0x45 <thomasvoss@live.com> 2021-02-03 18:12:48 +0100
commitadd7c63d4c5a859b1fddab8077b6c94afa8b38fb (patch)
tree65d0f46c80df5c26c17416e7d35ee5b33036bf78
parentfd2a3e806b73443c47d9d91b788496839f79e290 (diff)
Better time formatting
-rw-r--r--.clang-format18
-rw-r--r--main.js68
2 files changed, 48 insertions, 38 deletions
diff --git a/.clang-format b/.clang-format
index f7f31ac..b37ca62 100644
--- a/.clang-format
+++ b/.clang-format
@@ -12,8 +12,24 @@ AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
BinPackArguments: true
BinPackParameters: true
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
-BreakBeforeBraces: Attach
+BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
ColumnLimit: 100
ContinuationIndentWidth: 4
diff --git a/main.js b/main.js
index 6cf8855..93c3666 100644
--- a/main.js
+++ b/main.js
@@ -1,47 +1,23 @@
-function compute() {
- /* Initiate basic time variables */
- let h = 0;
- let m = 0;
- let s = 0;
- let ms = 0;
-
+function compute()
+{
/*
* Get framerate, start frame, and end frame from corresponding elements
* Double check they all have a value
*/
- let fps = parseInt(document.getElementById("framerate").value);
- let sframe = document.getElementById("startobj").value;
- let eframe = document.getElementById("endobj").value;
+ const fps = parseInt(document.getElementById("framerate").value);
+ const sframe = document.getElementById("startobj").value;
+ const eframe = document.getElementById("endobj").value;
if (typeof (sframe) === "undefined" || typeof (eframe) === "undefined"
|| typeof (fps) === "undefined")
return;
- /* Calculate framerate */
- let frames = (eframe - sframe) * fps;
- s = Math.floor(frames / fps);
- frames = frames % fps;
- ms = Math.round(frames / fps * 1000);
- if (ms < 10)
- ms = "00" + ms;
- else if (ms < 100)
- ms = "0" + ms;
-
- if (s >= 60) {
- m = Math.floor(s / 60);
- s = s % 60;
- s = s < 10 ? "0" + s : s;
- }
- if (m >= 60) {
- h = Math.floor(m / 60);
- m = m % 60;
- m = m < 10 ? "0" + m : m;
- }
+ const frames = (eframe - sframe) * fps;
+ const s = Math.floor(frames / fps);
/* Show the time and mod message in the DOM */
- let ftime =
- h.toString() + "h " + m.toString() + "m " + s.toString() + "s " + ms.toString() + "ms";
- let mod_message = `Mod Note: Retimed (Start: Frame ${sframe * fps}, End: ${
+ const ftime = time_format(s);
+ const mod_message = `Mod Note: Retimed (Start: Frame ${sframe * fps}, End: ${
eframe * fps}, FPS: ${fps}, Total Time: ${ftime})`;
document.getElementById("time").value = ftime;
@@ -50,8 +26,26 @@ function compute() {
document.getElementById("mod_message_button").disabled = false;
}
+/* Convert seconds to human readable time */
+function time_format(t)
+{
+ const h = ~~(time / 3600);
+ const m = ~~((time % 3600) / 60);
+ const s = ~~time % 60;
+ let ret = "";
+
+ if (h > 0)
+ ret += h + ":" + (m < 10 ? "0" : "");
+
+ ret += m + ":" + (s < 10 ? "0" : "");
+ ret += s;
+
+ return ret;
+}
+
/* Allow user to copy mod message to clipboard */
-function copy_mod_message() {
+function copy_mod_message()
+{
const text_area = document.getElementById("mod_message");
text_area.focus();
text_area.select();
@@ -82,9 +76,9 @@ const check_fps =
const parse_time = (event) => {
let inptext_frame = (JSON.parse(event.target.value)).lct;
if (typeof inptext_frame !== "undefined") {
- let fps = parseInt(document.getElementById("framerate").value);
- let frameFromObj = (time, fps) => Math.floor(time * fps) / fps;
- let fframe = frameFromObj(inptext_frame, fps);
+ const fps = parseInt(document.getElementById("framerate").value);
+ const frame_from_obj = (t, fps) => Math.floor(t * fps) / fps;
+ const fframe = frame_from_obj(inptext_frame, fps);
document.getElementById(event.target.id).value = `${fframe}`;
}
}