From 517372a2a313e2e32da23d87c4e1595ae4c9afa9 Mon Sep 17 00:00:00 2001
From: Ratnadeep Rajendra Kharade <92khra1mst@hft-stuttgart.de>
Date: Fri, 30 Oct 2020 14:43:37 +0100
Subject: [PATCH] added logic to roundoff seconds to nearest 30 and format in
hh:mm:ss
---
public/index.html | 2 +-
public/index.js | 43 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/public/index.html b/public/index.html
index c429598..c0f9bf5 100644
--- a/public/index.html
+++ b/public/index.html
@@ -113,7 +113,7 @@
-
Estimated Reading Time: min
+ Estimated Reading Time(hh:mm:ss): hours
Send your feedback on: behira.younes@univ-oran2.dz
diff --git a/public/index.js b/public/index.js
index 0ee1b49..ca553cc 100644
--- a/public/index.js
+++ b/public/index.js
@@ -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;
+}
--
GitLab