Skip to content

Commit

Permalink
[fixed] more month event layout issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Sep 13, 2015
1 parent bf0390d commit dade2b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/utils/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,18 @@ let dates = Object.assign(dateMath, {
)
},

duration(start, end, unit){
duration(start, end, unit, firstOfWeek){
if (unit === 'day') unit = 'date';
return Math.abs(dates[unit](start) - dates[unit](end))
return Math.abs(dates[unit](start, undefined, firstOfWeek) - dates[unit](end, undefined, firstOfWeek))
},

diff(dateA, dateB, unit){
if (!unit)
return Math.abs(+dateA - +dateB)

return Math.abs((+dateA / MILLI[unit]) - (+dateB / MILLI[unit]))
return Math.abs(
(+dates.startOf(dateA, unit) / MILLI[unit]) - (+dates.startOf(dateB, unit) / MILLI[unit])
)
},

week(date){
Expand Down
18 changes: 9 additions & 9 deletions src/utils/eventLevels.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import { accessor as get } from './accessors';
// }

export function eventSegments(event, first, last, { startAccessor, endAccessor, culture }){
let startOfWeek = localizer.startOfWeek(culture);
let start = dates.duration(first, dates.max(get(event, startAccessor), first), 'weekday', startOfWeek);
let slots = dates.diff(first, last, 'day')
let start = dates.max(get(event, startAccessor), first);
let end = dates.min(get(event, endAccessor), dates.add(last, 1, 'day'))

let span = Math.min(dates.duration(
dates.max(get(event, startAccessor), first)
, dates.min(get(event, endAccessor), dates.add(last, 1, 'day'))
, 'day'), 7);
let span = dates.diff(start, end, 'day');

span = Math.max(span, 1);
span = Math.min(Math.max(span, 1), slots);

let padding = dates.diff(first, start, 'day');

return {
event,
span,
left: start + 1,
right: Math.max(start + span, 1)
left: padding + 1,
right: Math.max(padding + span, 1)
}
}

Expand Down

0 comments on commit dade2b9

Please sign in to comment.