Advertisement
emesten

Untitled

Aug 13th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 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.  
  12. let hourDifference = 0;
  13. let dayDifference = 0;
  14.  
  15. if (currentDay === spawnDay) {
  16. hourDifference = spawnHour - currentHour;
  17. }
  18. else {
  19. hourDifference = (24 * dayDifference + (24 - currentHour)) + spawnHour;
  20. }
  21.  
  22. if (currentDay !== spawnDay && spawnDay === 0) {
  23. dayDifference = 6 - currentDay;
  24. }
  25.  
  26. else if (currentDay !== spawnDay && spawnDay !== 0 && currentDay > spawnDay) {
  27. dayDifference = 6 - currentDay - spawnDay;
  28. }
  29. else if (currentDay !== spawnDay && spawnDay !== 0 && currentDay < spawnDay) {
  30. dayDifference = spawnDay - currentDay - 1;
  31. }
  32. else {
  33. console.log('woops, send this to the admin: '+this.boss)
  34. }
  35.  
  36. let minuteDifference = spawnMinute - currentMinute;
  37. if (minuteDifference < 0) {
  38. minuteDifference = 59 + minuteDifference;
  39. hourDifference--;
  40. }
  41. minuteDifference--;
  42. let secondDifference = 60 - currentSecond;
  43.  
  44. this.secTillBoss = (hourDifference * 60 * 60 * 1000) + (minuteDifference * 60 * 1000) + (secondDifference * 1000);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement