Skip to content

Instantly share code, notes, and snippets.

@nkhil
Last active October 12, 2018 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkhil/d3ac32bb4385602f4d79300b8300963e to your computer and use it in GitHub Desktop.
Save nkhil/d3ac32bb4385602f4d79300b8300963e to your computer and use it in GitHub Desktop.
const endpoint = 'https://www.gov.uk/bank-holidays.json';
const ul = document.getElementById('holidays')
let bankHolidays;
let england;
fetch(endpoint)
.then(blob => blob.json())
.then(data => handleDates(data));
function handleDates(data) {
bankHolidays = data;
england = bankHolidays["england-and-wales"].events;
const now = new Date();
const thisMonth = now.getUTCMonth() + 1; //months from 1-12
const thisDay = now.getUTCDate();
const thisYear = now.getUTCFullYear();
const thisDate = thisYear + '-' +thisMonth + '-' +thisDay;
const html = england.map((items)=>{
const [year, month, date] = items.date.split("-");
if(Date.parse(thisDate) <= Date.parse(items.date)){
return `
<li>${items.title} <br/> <span class='yellow'>(${date} / ${month} / ${year})</span> </li>
`;
}
}).join('');
ul.innerHTML = html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment