diff --git a/resources/js/helpers/TimeFormatter.ts b/resources/js/helpers/TimeFormatter.ts new file mode 100644 index 0000000..785a10e --- /dev/null +++ b/resources/js/helpers/TimeFormatter.ts @@ -0,0 +1,43 @@ +export function timeFormatter(time: String): string { + const timeArray = time.split(':'); + const hours = timeArray[0]; + const minutes = timeArray[1]; + const seconds = timeArray[2].split('.')[0]; + let stringTime = ''; + if (parseInt(hours) > 0) { + stringTime += hours+':'; + } + if (parseInt(minutes) > 0 || parseInt(hours) > 0) { + stringTime += minutes+':'; + } + stringTime += seconds; + + if (parseInt(stringTime) === 0) { + stringTime = 'N/A'; + } + + return stringTime; +} + +export function formatFromSeconds(seconds: number): string { + let stringTime = ''; + let minutes = seconds / 60; + let hours = minutes / 60; + console.log(seconds, minutes, hours) + if (parseInt(hours) > 0) { + stringTime += (hours < 10) ? '0' : ''; + stringTime += parseInt(hours) + ':'; + seconds = seconds - (parseInt(hours) * 3600); + console.log(stringTime) + } + if (parseInt(hours) > 0 || parseInt(minutes) > 0) { + minutes = minutes - (parseInt(hours) * 60); + stringTime += (minutes < 10) ? '0' : ''; + stringTime += parseInt(minutes) + ':'; + seconds = seconds - (parseInt(minutes) * 60); + console.log(stringTime) + } + stringTime += seconds.toFixed(2); + console.log(stringTime) + return stringTime; +} \ No newline at end of file