From 2120ab8de5a2dc5842eda207e4e437566a560cba Mon Sep 17 00:00:00 2001 From: Rob Date: Sun, 22 Sep 2019 12:52:53 +0200 Subject: [PATCH] sort by date --- js/Schedule.js | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) 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(){ - - 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.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; + }); + this.events = allEvents; }