wmcmahan / react-native-calendar-events

📆 React Native Module for iOS and Android Calendar Events
MIT License
902 stars 291 forks source link

fetchAllEvents does not return multi-day events started before the start date #68

Closed alan-zetland closed 6 years ago

alan-zetland commented 7 years ago

Hi, I'm using this code as part of a rect-native app to display calendar events in a smart mirror - I've successfully retrieved the events, however I notice that it does not return any events that started before the "startDate" but are still ongoing.

Really simple code of course (I've hard-coded the dates for the example):

RNCalendarEvents.fetchAllEvents("2017-06-08T00:00:00.000Z", "2017-06-12T00:00:00.000Z")

It returns single day events (either allDay or start and finish within the same day), events that start on one of the days, but does return any events that started before the startDate, but finish either during this given period or beyond. I've tried setting the events to "allDay" or specific start finish times, but does not work.

Seems pretty basic functionality so I assumed I must be doing something wrong, any ideas, or is it a bug in the code?

Thanks.

wmcmahan commented 7 years ago

Hi @alan-zetland, it sounds like you need to create recurring events in the this case. By doing so, the start date should query the recurring instance's start date.

Ex:

RNCalendarEvents.saveEvent('Event Title', {
  startDate: '2017-06-08T00:00:00.000Z',
  endDate: '2017-06-08T00:12:00.000Z',
  recurrence: 'daily',
  // Note: "recurrenceEnd" has not been published to NPM yet,
  // but is in the master branch of this repo for iOS
  recurrenceEnd: '2017-06-09T00:00:00.000Z'
})
zalesky commented 7 years ago

@wmcmahan It's really great feature. Can you tell when it be available for Android?

wmcmahan commented 7 years ago

Hey @zalesky, hopefully soon. I just need to make time to get both iOS and Android recurrence rules at parity. The final structure will look something like:

{
  recurrenceRule: {
    frequency: 'weekly',
    interval: 2,
    occurrence: 2,
    endDate: (new Date()).toISOString()
  }
}
alan-zetland commented 7 years ago

Hi, thanks so much for getting back to me - I see what you are saying about recurring events, but that kind of clashes with the user experience - when creating a multi-day event, I don't think anyone would think of creating it as a recurring event across a number of days. For example, if I add a calendar event of "going on holiday" that lasts 3 weeks, I would simply set a start and end date of the one event, it would never occur to me to add it as a daily recurring event (although I agree it would then make your code work).

I've started working on a solution for my predicament by arbitrarily getting a much wider range of dates (eg going back a year) and getting all calendar events, then doing a comparison to see if any of the dates overlap - as opposed to a simple comparison of start dates. As I'm only building an app for my personal use, I'm not worried about the performance. I'll also see if there is some way I could fork your code and add some extra logic (although I'm not a Java expert so not exactly sure where to start).

Cheers for a good plugin though.

wmcmahan commented 7 years ago

Yes, I see your point. Currently, the query searches by a hard start and end date, not to be confused with all events that overlap these dates. You could adjust the query in the Android code here - L139 to account for events that touch or overlap a timespan.

alan-zetland commented 7 years ago

Thanks again for getting back to me - yes that was the point in the native code where I thought I would have to add some extra logic. I'll give it a shot and let you know if it turns into something that can be merged back in eventually.