Skip to content

Commit 917ed12

Browse files
renzonrenzon
authored andcommitted
Included countdown based on context date
1 parent 32eda19 commit 917ed12

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

‎pythonpro/checkout/templates/checkout/membership_lp_subscription_open.html‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,9 @@ <h5 class="modal-title">Formulário de Inscrição</h5>
12211221
</div>
12221222
</div>
12231223
<script type="application/javascript">
1224+
1225+
initCountDown(new Date({{promotion_end_date_milliseconds}}).getTime());
1226+
12241227
let phoneInput = document.getElementById('id_phone');
12251228
phoneInput.addEventListener('input', function (e) {
12261229
var x = e.target.value.replace(/\D/g, '').match(/(\d{0,2})(\d{0,5})(\d{0,4})/);
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
const second = 1000,
2-
minute = second * 60,
3-
hour = minute * 60,
4-
day = hour * 24;
1+
function initCountDown(countDown) {
2+
const second = 1000,
3+
minute = second * 60,
4+
hour = minute * 60,
5+
day = hour * 24;
6+
x = setInterval(function () {
57

6-
let countDown = new Date('Apr 17, 2020 11:59:59').getTime(),
7-
x = setInterval(function () {
8+
let now = new Date().getTime(),
9+
distance = countDown - now;
810

9-
let now = new Date().getTime(),
10-
distance = countDown - now;
11+
document.getElementsByClassName('days')[0].innerText = Math.floor(distance / (day)),
12+
document.getElementsByClassName('days')[1].innerText = Math.floor(distance / (day)),
13+
document.getElementsByClassName('hours')[0].innerText = Math.floor((distance % (day)) / (hour)),
14+
document.getElementsByClassName('hours')[1].innerText = Math.floor((distance % (day)) / (hour)),
15+
document.getElementsByClassName('minutes')[0].innerText = Math.floor((distance % (hour)) / (minute)),
16+
document.getElementsByClassName('minutes')[1].innerText = Math.floor((distance % (hour)) / (minute)),
17+
document.getElementsByClassName('seconds')[0].innerText = Math.floor((distance % (minute)) / second),
18+
document.getElementsByClassName('seconds')[1].innerText = Math.floor((distance % (minute)) / second);
1119

12-
document.getElementsByClassName('days')[0].innerText = Math.floor(distance / (day)),
13-
document.getElementsByClassName('days')[1].innerText = Math.floor(distance / (day)),
14-
document.getElementsByClassName('hours')[0].innerText = Math.floor((distance % (day)) / (hour)),
15-
document.getElementsByClassName('hours')[1].innerText = Math.floor((distance % (day)) / (hour)),
16-
document.getElementsByClassName('minutes')[0].innerText = Math.floor((distance % (hour)) / (minute)),
17-
document.getElementsByClassName('minutes')[1].innerText = Math.floor((distance % (hour)) / (minute)),
18-
document.getElementsByClassName('seconds')[0].innerText = Math.floor((distance % (minute)) / second),
19-
document.getElementsByClassName('seconds')[1].innerText = Math.floor((distance % (minute)) / second);
20+
if (distance < 0) {
21+
clearInterval(x);
22+
'Tempo esgotado!';
23+
}
2024

21-
if (distance < 0) {
22-
clearInterval(x);
23-
'Tempo esgotado!';
24-
}
25-
26-
}, second)
25+
}, second)
26+
}

0 commit comments

Comments
 (0)