Completed
Push — master ( 8beccd...205b41 )
by Megh
03:38
created

static/js/countdown.js   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 41
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 0
c 1
b 1
f 0
nc 1
dl 0
loc 41
rs 10
wmc 4
mnd 1
bc 4
fnc 3
bpm 1.3333
cpm 1.3333
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A countdown.js ➔ initializeClock 0 23 1
1
function getTimeRemaining(endtime) {
0 ignored issues
show
Unused Code introduced by
The parameter endtime is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
2
  var t = Date.parse("Jan 27, 2018") - Date.parse(new Date());
3
  var seconds = Math.floor((t / 1000) % 60);
4
  var minutes = Math.floor((t / 1000 / 60) % 60);
5
  var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
6
  var days = Math.floor(t / (1000 * 60 * 60 * 24));
7
  return {
8
    'total': t,
9
    'days': days,
10
    'hours': hours,
11
    'minutes': minutes,
12
    'seconds': seconds
13
  };
14
}
15
16
function initializeClock(id, endtime) {
17
  var clock = document.getElementById(id);
18
  var daysSpan = clock.querySelector('.days');
19
  var hoursSpan = clock.querySelector('.hours');
20
  var minutesSpan = clock.querySelector('.minutes');
21
  var secondsSpan = clock.querySelector('.seconds');
22
23
  function updateClock() {
24
    var t = getTimeRemaining(endtime);
25
26
    daysSpan.innerHTML = t.days;
27
    hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
28
    minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
29
    secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
30
31
    if (t.total <= 0) {
32
      clearInterval(timeinterval);
33
    }
34
  }
35
36
  updateClock();
37
  var timeinterval = setInterval(updateClock, 1000);
0 ignored issues
show
Unused Code introduced by
The assignment to variable timeinterval seems to be never used. Consider removing it.
Loading history...
38
}
39
40
var deadline = new Date(Date.parse(new Date()) + 15 * 24 * 60 * 60 * 1000);
41
initializeClock('clockdiv', deadline);
42