Commit 517372a2 authored by Ratnadeep Rajendra Kharade's avatar Ratnadeep Rajendra Kharade
Browse files

added logic to roundoff seconds to nearest 30 and format in hh:mm:ss

parent 7eeebd02
Pipeline #1131 passed with stages
in 2 seconds
......@@ -113,7 +113,7 @@
</div>
<div id="calculate-time-element" style="display: none;">
<div class="title">
<h2>Estimated Reading Time: <span id="reading-time-element"></span> min</h2>
<h2>Estimated Reading Time(hh:mm:ss): <span id="reading-time-element"></span> hours</h2>
</div>
<div>
Send your feedback on: behira.younes@univ-oran2.dz
......
......@@ -139,8 +139,7 @@ function calculateReadingTime() {
//x = (inputObj.numberOfCharacters * inputObj.schoolLevel * inputObj.category);
let combination = inputObj.schoolLevel + '' + inputObj.category;
console.log(combination);
let C = inputObj.numberOfCharacters;
switch (combination) {
......@@ -209,11 +208,47 @@ function calculateReadingTime() {
break;
}
// set value to html element
// get modulo division of x for rounding off till 30 seconds
let xMod60 = x % 60;
if (xMod60 <= 15) {
roundOff = 0;
}
if (xMod60 > 15 && xMod60 <= 30) {
roundOff = 30;
}
if (xMod60 > 30 && xMod60 <= 45) {
roundOff = 30;
}
if (xMod60 > 45) {
roundOff = 60;
}
// subtract mod seconds and add rounded off seconds
let roundedOffSeconds = x - xMod60 + roundOff;
// get formatted time in hh:mm:ss format
let formattedTime = getFormattedTime(roundedOffSeconds)
// set time value to html element
var s = document.getElementById('reading-time-element');
s.innerHTML = x;
s.innerHTML = formattedTime;
// display html element which shows time
let element = document.getElementById('calculate-time-element');
element.style.display = "block";
}
}
// function getFormatted time
// accepts seconds value and returns in hh:mm:ss format
function getFormattedTime(totalSeconds) {
let hours = Math.floor(totalSeconds / 3600);
totalSeconds %= 3600;
let minutes = Math.floor(totalSeconds / 60);
let seconds = totalSeconds % 60;
minutes = String(minutes).padStart(2, "0");
hours = String(hours).padStart(2, "0");
seconds = String(seconds).padStart(2, "0");
return hours + ":" + minutes + ":" + seconds;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment