diff --git a/js/Schedule.js b/js/Schedule.js index 6f90be3..dd39bc0 100644 --- a/js/Schedule.js +++ b/js/Schedule.js @@ -84,26 +84,33 @@ class Schedule { getEvents() { let allEvents = []; - if (this.events.length == 0 ){ - //this.schedule.find('event').toArray(); - var now = this.now - this.schedule.find('event').each( function(){ + //this.schedule.find('event').toArray(); + var now = this.now + this.schedule.find('event').each( function(){ + + var eventStart = new Date($(this).children('date').text()); + var tenHours = 36000000; + if ((eventStart - now) >= 0 && (eventStart - now) < tenHours){ + allEvents.push({ + title: $(this).children('title').text(), + room: $(this).children('room').text(), + date: $(this).children('date').text(), + start: $(this).children('start').text(), + duration: $(this).children('duration').text(), + abstract: $(this).children('abstract').text().slice(0, 256), + persons: $(this).children('persons').text(), + }); + } + }); + + allEvents.sort((a,b) => { + + var a_start = new Date(a.date).getTime(); + var b_start = new Date(b.date).getTime(); + console.log(a_start, b_start, a_start - b_start); + return a_start - b_start; + }); - var eventStart = new Date($(this).children('date').text()); - var tenHours = 36000000; - if ((eventStart - now) >= 0 && (eventStart - now) < tenHours){ - allEvents.push({ - title: $(this).children('title').text(), - room: $(this).children('room').text(), - date: $(this).children('date').text(), - start: $(this).children('start').text(), - duration: $(this).children('duration').text(), - abstract: $(this).children('abstract').text().slice(0, 256), - persons: $(this).children('persons').text(), - }); - } - }); - } this.events = allEvents; }