Advertisement
emesten

Untitled

Aug 13th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. calculateTime() {
  2. const d = new Date();
  3. const currentDay = d.getDay();
  4. const currentHour = d.getHours();
  5. const currentMinute = d.getMinutes();
  6. const currentSecond = d.getSeconds();
  7.  
  8. const spawnDay = this.dayStringToInt(this.boss.DAYOFWEEK);
  9. const spawnHour = parseInt(this.boss.SPAWNSAT.HOUR);
  10. const spawnMinute = parseInt(this.boss.SPAWNSAT.MINUTE);
  11. let dayDifference = 0;
  12.  
  13. if (currentDay !== spawnDay && spawnDay === 0) {
  14. dayDifference = 6 - currentDay;
  15. }
  16. else if (currentDay !== spawnDay && spawnDay !== 0 && currentDay > spawnDay) {
  17. dayDifference = 6 - currentDay - spawnDay;
  18. }
  19. else if (currentDay !== spawnDay && spawnDay !== 0 && currentDay < spawnDay) {
  20. dayDifference = spawnDay - currentDay - 1;
  21. }
  22. else {
  23. console.log('woops, send this to the admin: '+this.boss)
  24. }
  25.  
  26. let hourDifference = 0;
  27. if (currentDay === spawnDay) {
  28. hourDifference = spawnHour - currentHour;
  29. }
  30. else {
  31. hourDifference = (24 * dayDifference + (24 - currentHour)) + spawnHour;
  32. }
  33.  
  34. let minuteDifference = spawnMinute - currentMinute;
  35. if (minuteDifference < 0) {
  36. minuteDifference = 59 + minuteDifference;
  37. hourDifference--;
  38. }
  39. minuteDifference--;
  40. let secondDifference = 60 - currentSecond;
  41.  
  42. this.secTillBoss = (hourDifference * 60 * 60 * 1000) + (minuteDifference * 60 * 1000) + (secondDifference * 1000);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement