Skip to content

Commit

Permalink
[fixed] event layout sort
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Oct 28, 2015
1 parent 0574eed commit 0eeb43f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/utils/eventLevels.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,20 @@ export function segsOverlap(seg, otherSegs) {


export function sortEvents(evtA, evtB, { startAccessor, endAccessor, allDayAccessor }) {
let durA = dates.duration(
get(evtA, startAccessor)
, get(evtA, endAccessor)
, 'day')
, durB = dates.duration(
let startSort = +dates.startOf(get(evtA, startAccessor), 'day') - +dates.startOf(get(evtB, startAccessor), 'day')

let durA = dates.diff(
get(evtA, startAccessor)
, dates.ceil(get(evtA, endAccessor), 'day')
, 'day');

let durB = dates.diff(
get(evtB, startAccessor)
, get(evtB, endAccessor)
, dates.ceil(get(evtB, endAccessor), 'day')
, 'day');

return (+get(evtA, startAccessor) - +get(evtB, startAccessor))
|| (durB - durA)
|| !!get(evtA, allDayAccessor) - !!get(evtB, allDayAccessor)
return startSort // sort by start Day first
|| Math.max(durB, 1) - Math.max(durA, 1) // events spanning multiple days go first
|| !!get(evtB, allDayAccessor) - !!get(evtA, allDayAccessor) // then allDay single day events
|| +get(evtA, startAccessor) - +get(evtB, startAccessor) // then sort by start time
}

0 comments on commit 0eeb43f

Please sign in to comment.