@@ -8,49 +8,48 @@ const InitializeDateCountDown = () => {
88
99 const targetDate = document . querySelector ( '[wt-datecount-element="target-date"]' ) ;
1010
11- if ( ! targetDate ) return ;
11+ if ( ! targetDate ) return ;
1212
1313 var countDownDate = new Date ( targetDate . innerText ) . getTime ( ) ;
1414
15- if ( ! isDateValid ( countDownDate ) ) return ;
15+ if ( ! isDateValid ( countDownDate ) ) return ;
1616
1717 // Update the count down every 1 second
18- var x = setInterval ( function ( ) {
19-
20- // Get today's date and time
21- var now = new Date ( ) . getTime ( ) ;
22-
23- // Find the distance between now and the count down date
24- var distance = countDownDate - now ;
25-
26- const _targetYear = document . querySelector ( '[wt-datecount-element="target-year"]' ) ;
27- const _targetMonth = document . querySelector ( '[wt-datecount-element="target-month"]' ) ;
28- const _targetDay = document . querySelector ( '[wt-datecount-element="target-day"]' ) ;
29- const _targetHour = document . querySelector ( '[wt-datecount-element="target-hour"]' ) ;
30- const _targetMin = document . querySelector ( '[wt-datecount-element="target-minute"]' ) ;
31- const _targetSec = document . querySelector ( '[wt-datecount-element="target-second"]' ) ;
32-
33-
34- // Time calculations for days, hours, minutes and seconds
35- var year = Math . floor ( distance / ( 1000 * 60 * 60 * 24 ) ) ;
36- var month = Math . floor ( distance / ( 1000 * 60 * 60 * 24 ) ) ;
37- var second = Math . floor ( distance / ( 1000 * 60 * 60 * 24 ) ) ;
38- var days = Math . floor ( distance / ( 1000 * 60 * 60 * 24 ) ) ;
39- var hours = Math . floor ( ( distance % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 ) ) ;
40- var minutes = Math . floor ( ( distance % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 ) ) ;
41- var seconds = Math . floor ( ( distance % ( 1000 * 60 ) ) / 1000 ) ;
42-
43- // Output the result in an element with id="demo"
44- document . getElementById ( "demo" ) . innerHTML = days + "d " + hours + "h "
45- + minutes + "m " + seconds + "s " ;
46-
47-
48-
49-
50- // If the count down is over, write some text
51- if ( distance < 0 ) {
52- clearInterval ( x ) ;
53- document . getElementById ( "demo" ) . innerHTML = "EXPIRED" ;
54- }
18+ var x = setInterval ( function ( ) {
19+
20+ // Get today's date and time
21+ var now = new Date ( ) . getTime ( ) ;
22+
23+ // Find the distance between now and the count down date
24+ var distance = countDownDate - now ;
25+
26+ // If the count down is over, write some text
27+ if ( distance < 0 ) {
28+ clearInterval ( x ) ;
29+ document . getElementById ( "demo" ) . innerHTML = "EXPIRED" ;
30+ }
31+
32+ const _targetYear = document . querySelector ( '[wt-datecount-element="target-year"]' ) ;
33+ const _targetMonth = document . querySelector ( '[wt-datecount-element="target-month"]' ) ;
34+ const _targetDay = document . querySelector ( '[wt-datecount-element="target-day"]' ) ;
35+ const _targetHour = document . querySelector ( '[wt-datecount-element="target-hour"]' ) ;
36+ const _targetMin = document . querySelector ( '[wt-datecount-element="target-minute"]' ) ;
37+ const _targetSec = document . querySelector ( '[wt-datecount-element="target-second"]' ) ;
38+
39+ // Time calculations for days, hours, minutes and seconds
40+ var year = Math . floor ( distance / ( 1000 * 60 * 60 * 24 ) ) ;
41+ var month = Math . floor ( distance / ( 1000 * 60 * 60 * 24 ) ) ;
42+ var days = Math . floor ( distance / ( 1000 * 60 * 60 * 24 ) ) ;
43+ var hours = Math . floor ( ( distance % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 ) ) ;
44+ var minutes = Math . floor ( ( distance % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 ) ) ;
45+ var seconds = Math . floor ( ( distance % ( 1000 * 60 ) ) / 1000 ) ;
46+
47+ if ( _targetYear ) _targetYear . innerText = year
48+ if ( _targetMonth ) _targetMonth . innerText = month
49+ if ( _targetDay ) _targetDay . innerText = days
50+ if ( _targetHour ) _targetHour . innerText = hours
51+ if ( _targetMin ) _targetMin . innerText = minutes
52+ if ( _targetSec ) _targetSec . innerText = seconds
53+
5554 } , 1000 ) ;
5655}
0 commit comments