Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. <?php if (new DateTime() < new DateTime( "18:00:00")) { ?>
  2.  
  3. <script type="text/javascript">
  4. var check = 0;
  5. /*set the countdown hour*/
  6. var countDownTo = 18;
  7. var CDown = function() {
  8. this.state = 0; // if initialized
  9. this.counts = []; // array holding countdown date objects and id
  10. to print to {d:new Date(2013,11,18,18,54,36), id:"countbox1"}
  11. this.interval = null; // setInterval object
  12. }
  13.  
  14. CDown.prototype = {
  15. init: function() {
  16. this.state = 1;
  17. var self = this;
  18. this.interval = window.setInterval(function() {
  19. self.tick();
  20. }, 1000);
  21. },
  22. add: function(date, id) {
  23. this.counts.push({
  24. d: date,
  25. id: id
  26. });
  27. this.tick();
  28. if (this.state == 0) this.init();
  29. },
  30. expire: function(idxs) {
  31. for (var x in idxs) {
  32. this.display(this.counts[idxs[x]], "Now!");
  33. this.counts.splice(idxs[x], 1);
  34. }
  35.  
  36. },
  37. format: function(r) {
  38. var out = "";
  39. if (r.d != 0) {
  40. out += r.d + " " + ((r.d == 1) ? "day" : "days") + ", ";
  41. }
  42. if (r.h != 0) {
  43. out += r.h + " " + ((r.h == 1) ? "hour" : "hours") + ", ";
  44. }
  45. out += r.m + " " + ((r.m == 1) ? "min" : "mins") + ", ";
  46. out += r.s + " " + ((r.s == 1) ? "sec" : "secs") + ", ";
  47.  
  48. return out.substr(0, out.length - 2);
  49. },
  50. math: function(work) {
  51. var y = w = d = h = m = s = ms = 0;
  52.  
  53. ms = ("" + ((work % 1000) + 1000)).substr(1, 3);
  54. work = Math.floor(work / 1000); //kill the "milliseconds" so just
  55. secs
  56.  
  57. y = Math.floor(work / 31536000); //years (no leapyear support)
  58. w = Math.floor(work / 604800); //weeks
  59. d = Math.floor(work / 86400); //days
  60. work = work % 86400;
  61.  
  62. h = Math.floor(work / 3600); //hours
  63. work = work % 3600;
  64.  
  65. m = Math.floor(work / 60); //minutes
  66. work = work % 60;
  67.  
  68. s = Math.floor(work); //seconds
  69.  
  70.  
  71.  
  72. return {
  73. y: y,
  74. w: w,
  75. d: d,
  76. h: h,
  77. m: m,
  78. s: s,
  79. ms: ms
  80. };
  81. },
  82. tick: function() {
  83. var now = (new Date()).getTime(),
  84. expired = [],
  85. cnt = 0,
  86. amount = 0;
  87.  
  88. if (this.counts)
  89. for (var idx = 0, n = this.counts.length; idx < n; ++idx) {
  90. cnt = this.counts[idx];
  91. amount = cnt.d.getTime() - now; //calc milliseconds between
  92. dates
  93.  
  94. // if time is already past
  95. if (amount < 0) {
  96. expired.push(idx);
  97. }
  98. // date is still good
  99. else {
  100. this.display(cnt, this.format(this.math(amount)));
  101. }
  102. }
  103.  
  104. // deal with any expired
  105. if (expired.length > 0) this.expire(expired);
  106.  
  107. // if no active counts, stop updating
  108. if (this.counts.length == 0) window.clearTimeout(this.interval);
  109.  
  110. },
  111. display: function(cnt, msg) {
  112. if (msg == `Now!`) {
  113. check = 1;
  114. msg = ``;
  115. var cdown = new CDown();
  116. var currentdate = new Date();
  117. var year = currentdate.getFullYear();
  118. var month = currentdate.getMonth();
  119. var day = currentdate.getDate() + 1;
  120. var currenthour = currentdate.getHours();
  121. /*perform check here*/
  122. if (countDownTo == 1) {
  123. countDownTo = 0;
  124. } else {
  125. countDownTo = 18;
  126. }
  127. var hour = countDownTo;
  128. var minute = 0;
  129. var second = 0;
  130. cdown.add(new Date(year, month, day, hour, minute, second),
  131. "countbox1");
  132. } else {
  133. check = 0;
  134. }
  135. if (countDownTo == 0) msg = ``;
  136. document.getElementById(cnt.id).innerHTML = msg;
  137.  
  138.  
  139. }
  140. };
  141.  
  142. window.onload = function() {
  143. var cdown = new CDown();
  144. var currentdate = new Date();
  145. var year = currentdate.getFullYear();
  146. var month = currentdate.getMonth();
  147. var day = currentdate.getDate();
  148. var hour = countDownTo;
  149. var minute = 0;
  150. var second = 0;
  151. cdown.add(new Date(year, month, day, hour, minute, second),
  152. "countbox1");
  153. };
  154. </script>
  155.  
  156. <h2>Time till Reset:</h2>
  157. <div style="font-size:25px; margin-top=10px;color:blue; font-
  158. weight:bold;" id="countbox1"></div></code>
  159.  
  160. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement