File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -149,6 +149,26 @@ $('.day-second').click(showSecondDayEvents);
149149
150150// Dynamic schedule code
151151
152+ function sortEvents ( a , b ) {
153+ // We can sort by start/end here because the ISO 8061
154+ // timestamps given by the server are lexicographically
155+ // sortable.
156+
157+ if ( a . start < b . start ) { // if a starts before b...
158+ return - 1 ; // ...then a goes before b
159+ } else if ( a . start > b . start ) { // if a starts after b...
160+ return 1 ; // ...then b goes before a
161+ } else {
162+ if ( a . end < b . end ) { // if a ends before b...
163+ return - 1 ; // ...then a goes before b
164+ } else if ( a . end > b . end ) { // if a ends after b...
165+ return 1 ; // ...then b goes before a
166+ } else {
167+ return 0 ;
168+ }
169+ }
170+ }
171+
152172function convertDate ( date ) {
153173 let output = '' ;
154174
@@ -185,6 +205,9 @@ function handleEventData(events) {
185205 showSecondDayEvents ( ) ;
186206 }
187207
208+ // need to sort events by start/end times instead of IDs
209+ events . sort ( sortEvents ) ;
210+
188211 events . forEach ( event => {
189212 let startDate = new Date ( event . start ) ; // convert ISO 8601 -> Date object
190213
You can’t perform that action at this time.
0 commit comments