Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. async function getHolidays(year)
  2. {
  3. const response = await fetch("https://calendarific.com/api/v2/holidays?&api_key=8a467e39a9ae7875410a03765fbab59fbd7ed3e8&country=hr&year="+year+"&fbclid=IwAR2_T3wnW25Ld4olqdW-I_ra59iuLZAKkBmGY1TqmNa0SoeX9i7TEke1obg");
  4. const jsonresponse = await response.json();
  5. return jsonresponse.response.holidays;
  6. }
  7.  
  8. function calculateSortIndex(holiday)
  9. {
  10. holiday.sortIndex=holiday.date.datetime.year*100000000+holiday.date.datetime.month*1000+holiday.date.datetime.day;
  11. }
  12.  
  13. async function getNextDate(day, month, year)
  14. {
  15. day = parseInt(day);
  16. month = parseInt(month);
  17. year = parseInt(year);
  18. var currentIndex = year*100000000+month*1000+day;
  19.  
  20. var year2019 = await getHolidays("2019");
  21. var year2020 = await getHolidays("2020");
  22.  
  23. var bothyears = year2019.concat(year2020);
  24.  
  25. bothyears.forEach(calculateSortIndex);
  26.  
  27. bothyears.sort((a, b) => a.sortIndex - b.sortIndex);
  28.  
  29. var date = null;
  30. for (var i=0;i<bothyears.length;i++)
  31. {
  32. if (currentIndex < bothyears[i].sortIndex)
  33. return bothyears[i];
  34. }
  35.  
  36. return null;
  37. }
  38.  
  39. document.getElementById("basicFetchButton").addEventListener("click", async function(){
  40.  
  41.  
  42. nextDate= await getNextDate("14","09","2019");
  43. if (nextDate)
  44. console.log(JSON.stringify(nextDate));
  45.  
  46.  
  47.  
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement