From a2aff2eae516a851266bfa21591e658da10837b3 Mon Sep 17 00:00:00 2001 From: Martin Aspeli Date: Sun, 29 Nov 2015 23:03:46 +0000 Subject: [PATCH 1/2] Fix bug whereby events crossing year boundary could be hidden Date maths is hard. :) If you have an event that finishes in an earlier month in a later year, it could be hidden by the previous logic. Feels like it should be possible to do this with moment().isBetween(), but it kind of gets a bit tricky because we don't check against a specific day. --- src/ReactEventCalendar.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ReactEventCalendar.js b/src/ReactEventCalendar.js index 64d8794..0b13c21 100644 --- a/src/ReactEventCalendar.js +++ b/src/ReactEventCalendar.js @@ -81,7 +81,11 @@ class EventCalendar extends React.Component { if (eventStartInView || eventEndInView) { // Asserts event's first or last day is visible in this month view eventMeta.isVisibleInView = true; - } else if (eventStart.month < this.props.month && eventEnd.month > this.props.month) { + } else if ( + (eventStart.year < this.props.year) || + (eventEnd.year > this.props.year) || + (eventStart.year === this.props.year && eventStart.month < this.props.month && eventEnd.month > this.props.month) + ) { // Asserts at least part of month is eventMeta.isVisibleInView = true; } From 1635286f109b342b0c65332500effa7962b61ed1 Mon Sep 17 00:00:00 2001 From: Martin Aspeli Date: Mon, 30 Nov 2015 15:15:53 +0000 Subject: [PATCH 2/2] Properly fix the date logic --- src/ReactEventCalendar.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ReactEventCalendar.js b/src/ReactEventCalendar.js index 0b13c21..29854ab 100644 --- a/src/ReactEventCalendar.js +++ b/src/ReactEventCalendar.js @@ -82,9 +82,8 @@ class EventCalendar extends React.Component { // Asserts event's first or last day is visible in this month view eventMeta.isVisibleInView = true; } else if ( - (eventStart.year < this.props.year) || - (eventEnd.year > this.props.year) || - (eventStart.year === this.props.year && eventStart.month < this.props.month && eventEnd.month > this.props.month) + (eventStart.year < this.props.year || (eventStart.year === this.props.year && eventStart.month < this.props.month)) && + (eventEnd.year > this.props.year || (eventEnd.year === this.props.year && eventEnd.month > this.props.month)) ) { // Asserts at least part of month is eventMeta.isVisibleInView = true; @@ -154,10 +153,10 @@ class EventCalendar extends React.Component { getCalendarDayObject(date) { const dateArray = date.split('-'); return { - year: dateArray[0], + year: parseInt(dateArray[0], 10), // Subtract 1 from month to allow for human declared months - month: dateArray[1] - 1, - day: dateArray[2], + month: parseInt(dateArray[1], 10) - 1, + day: parseInt(dateArray[2], 10), }; }