Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pado
Behira Younes
Commits
517372a2
Commit
517372a2
authored
Oct 30, 2020
by
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
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
public/index.html
View file @
517372a2
...
...
@@ -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
...
...
public/index.js
View file @
517372a2
...
...
@@ -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
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment