JSFiddle - React, Tailwind, and code Playground
JavaScript
function getTimeRemaining(endtime) {
var t = Date.parse(endtime) - Date.parse(new Date());
return {
'total': t,
'days': Math.floor(t / (1000 * 60 * 60 * 24)),
'hours': Math.floor((t / (1000 * 60 * 60)) % 24),
'minutes': Math.floor((t / 1000 / 60) % 60)
};
}
// City Selector
var events_informations = {
'belo-horizonte': {
'title': 'Belo Horizonte',
'date': '08/07/2017',
'place': 'Dayrell Hotel - a partir das 8:00',
'imagePath': 'img/cities/bh/belo-horizonte-2.jpg',
'btnBuyNow': 'https://www.sympla.com.br/',
'btnDestinePage': '/belo-horizonte',
'mapPlace': {
lat: -19.9226186,
lng: -43.9401089
},
'datetime': new Date(2017,5,20,8,30).toISOString()
}
};
console.log(getNextDestines(events_informations));
function getNextDestines(events_informations) {
var nextDestines = [];
var keys = Object.keys(events_informations);
for (var i = 0; i < keys.length; i++) {
var today = new Date();
var date = new Date(events_informations[keys[i]]['datetime']);
if (date.getTime() > today.getTime()) {
nextDestines.push(events_informations[keys[i]]['title'], events_informations[keys[i]]['date'], events_informations[keys[i]]['place']);
}
}
return nextDestines;
};