From dade2b9be36ab46bfc1ea3c92fe12bbe02909968 Mon Sep 17 00:00:00 2001 From: jquense Date: Sun, 13 Sep 2015 19:48:17 +0300 Subject: [PATCH] [fixed] more month event layout issues --- src/utils/dates.js | 8 +++++--- src/utils/eventLevels.js | 18 +++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/utils/dates.js b/src/utils/dates.js index 5a8b86ea4..4a5c94275 100644 --- a/src/utils/dates.js +++ b/src/utils/dates.js @@ -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){ diff --git a/src/utils/eventLevels.js b/src/utils/eventLevels.js index 2c569c148..4538768f8 100644 --- a/src/utils/eventLevels.js +++ b/src/utils/eventLevels.js @@ -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) } }