File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,27 @@ $('.day-first').click(function() {
147
147
} ) ;
148
148
$ ( '.day-second' ) . click ( showSecondDayEvents ) ;
149
149
150
- // Dynamic schedule code (sample API data)
150
+ // Dynamic schedule code
151
+
152
+ function compareEvents ( 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
+ }
151
171
152
172
function convertDate ( date ) {
153
173
let output = '' ;
@@ -185,6 +205,9 @@ function handleEventData(events) {
185
205
showSecondDayEvents ( ) ;
186
206
}
187
207
208
+ // need to sort events by start/end times instead of IDs
209
+ events . sort ( compareEvents ) ;
210
+
188
211
events . forEach ( event => {
189
212
let startDate = new Date ( event . start ) ; // convert ISO 8601 -> Date object
190
213
You can’t perform that action at this time.
0 commit comments