Last active
October 12, 2018 08:40
-
-
Save nkhil/d3ac32bb4385602f4d79300b8300963e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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