summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-18 16:52:11 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:06:04 +0200
commitf8f617c97fcb2df3dbefc9527d974151e367cb60 (patch)
treef6405aa54f73b66220f36e3a388725f71d023cfb /src/util
parent9f86ae6de969baa625e3341c796c64f63b5153ce (diff)
Implement basic experiment mode with timeline
The timeline doesn't trigger anything yet, but the visual element is in place and connected.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/date-time.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/util/date-time.js b/src/util/date-time.js
index ef3524db..3ec6b671 100644
--- a/src/util/date-time.js
+++ b/src/util/date-time.js
@@ -88,7 +88,7 @@ export function getCurrentDateTime() {
* Pads the given integer to have at least two digits.
*
* @param integer An integer to be padded.
- * @returns {string} A string containing the padded integer
+ * @returns {string} A string containing the padded integer.
*/
export function addPaddingToTwo(integer) {
if (integer < 10) {
@@ -97,3 +97,25 @@ export function addPaddingToTwo(integer) {
return integer.toString();
}
}
+
+/**
+ * Formats the given number of seconds/ticks to a formatted time representation.
+ *
+ * @param seconds The number of seconds.
+ * @returns {string} A string representation of that amount of second, in the from of HH:MM:SS.
+ */
+export function convertSecondsToFormattedTime(seconds) {
+ if (seconds <= 0) {
+ return "00:00:00";
+ }
+
+ let hour = Math.floor(seconds / 3600);
+ let minute = Math.floor(seconds / 60) % 60;
+ let second = seconds % 60;
+
+ hour = isNaN(hour) ? 0 : hour;
+ minute = isNaN(minute) ? 0 : minute;
+ second = isNaN(second) ? 0 : second;
+
+ return addPaddingToTwo(hour) + ":" + addPaddingToTwo(minute) + ":" + addPaddingToTwo(second);
+}