From f8f617c97fcb2df3dbefc9527d974151e367cb60 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Mon, 18 Sep 2017 16:52:11 +0200 Subject: Implement basic experiment mode with timeline The timeline doesn't trigger anything yet, but the visual element is in place and connected. --- src/util/date-time.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/util/date-time.js') 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); +} -- cgit v1.2.3