Skip to content

Commit 390ef13

Browse files
committed
Countdown stop
1 parent 62d9ce9 commit 390ef13

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎js/counter.js‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var intSec, intMin, intHour, intDay;
2-
var deadline = new Date(2013, 11, 26, 23, 21, 00, 00);
1+
var intSec;
2+
var deadline = new Date(2014, 0, 15, 20, 00, 00, 00);
33

44
var calc = function(type, func) {
55
$('.counter.'+type+' .to')
@@ -33,8 +33,6 @@ var getSec = function(next) {
3333

3434
if (sec === 60) {
3535
sec = 0;
36-
} else if (sec === 61) {
37-
sec = 1;
3836
}
3937

4038
return (sec < 10 ? '0' + sec : sec);
@@ -156,24 +154,32 @@ calc("sec", getSec);
156154
calc("min", getMin);
157155
calc("hour", getHour);
158156
calc("day", getDay);
159-
if (parseInt(getDay(false)) !== -1) {
157+
var today = new Date();
158+
if (daysUntil(today, deadline) !== -1) {
160159
intSec = setInterval(function() {
161160
calc("sec", getSec);
162161

163-
if (parseInt(getSec(false)) === 0) {
162+
var actSec = parseInt(getSec(false));
163+
if (actSec === 0) {
164164
calc("min", getMin);
165-
165+
166166
if (parseInt(getMin(false)) === 0) {
167167
calc("hour", getHour);
168168

169169
if (parseInt(getHour(false)) === 0) {
170170
calc("day", getDay);
171171
}
172172
}
173+
} else if (
174+
(actSec === 1)
175+
&& (parseInt(getMin(false)) === 1)
176+
&& (parseInt(getHour(false)) === 1)
177+
&& (parseInt(getDay(false)) === 0)) {
178+
console.log("STOP!");
179+
clearInterval(intSec);
173180
}
174181
}, 1000);
175182
}
176-
var today = new Date();
177183
console.log(daysUntil(today, deadline));
178184
console.log(hoursUntil(today, deadline));
179185
console.log(minsUntil(today, deadline));

0 commit comments

Comments
 (0)