sort by date

This commit is contained in:
Rob 2019-09-22 12:52:53 +02:00
parent 1d1d3e6761
commit 2120ab8de5
1 changed files with 26 additions and 19 deletions

View File

@ -84,26 +84,33 @@ class Schedule {
getEvents() getEvents()
{ {
let allEvents = []; let allEvents = [];
if (this.events.length == 0 ){ //this.schedule.find('event').toArray();
//this.schedule.find('event').toArray(); var now = this.now
var now = this.now this.schedule.find('event').each( function(){
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; this.events = allEvents;
} }