Advertisement
emesten

Untitled

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