From e476c671d13244bc9facd851804d4f2472094675 Mon Sep 17 00:00:00 2001 From: lrdossan Date: Fri, 2 Aug 2024 11:22:14 +0200 Subject: [PATCH] optimised the frontend method that handles the display of transition times in HH:MM format --- caimira/apps/calculator/static/js/co2_form.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/caimira/apps/calculator/static/js/co2_form.js b/caimira/apps/calculator/static/js/co2_form.js index 91113142..3eccece9 100644 --- a/caimira/apps/calculator/static/js/co2_form.js +++ b/caimira/apps/calculator/static/js/co2_form.js @@ -283,17 +283,13 @@ function validateCO2Form() { } function displayTransitionTimesHourFormat(start, stop) { - var minutes_start = ((start % 1) * 60).toPrecision(2); - var minutes_stop = ((stop % 1) * 60).toPrecision(2); - return ( - Math.floor(start) + - ":" + - (minutes_start != "0.0" ? minutes_start : "00") + - " - " + - Math.floor(stop) + - ":" + - (minutes_stop != "0.0" ? minutes_stop : "00") - ); + const formatTime = (time) => { + const hours = Math.floor(time); + const minutes = Math.round((time % 1) * 60); + return `${hours}:${minutes.toString().padStart(2, '0')}`; + }; + + return `${formatTime(start)} - ${formatTime(stop)}`; } function displayFittingData(json_response) {