Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14953] iOS: Ti.Calendar getEventsBetweenDates is not working

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2016-02-22T19:48:39.000+0000
Affected Version/sRelease 3.2.0
Fix Version/sRelease 5.4.0
ComponentsiOS
Labelsdefect, ios, qe-5.4.0
ReporterDan Tamas
AssigneeAngel Petkov
Created2013-08-19T14:22:20.000+0000
Updated2016-08-08T19:25:52.000+0000

Description

on iOS getEventsBetweenDates method is not working: - it is misspelled: **getEventsBeteenDates** (missing "w") - if I call the method this way, no matter what I'm trying to put as arguments (dates or strings) is not working if I put a strings (like "2014-02-19T16:17:46+01:00") I get
"*** -[EKEventStore predicateForEventsWithStartDate:endDate:calendars:]: startDate is nil";
if I put dates I get
message = "Invalid type passed to function";
nativeLocation = "-[TiCalendarCalendar getEventsBeteenDates:] (TiCalendarCalendar.m:157)";
nativeReason = "expected: String, was: __NSDate";

Comments

  1. Sean Hunter 2013-08-24

    Here is the fix for now... After fixing the misspelling in TiCalendarCalendar.m, the getEventsBetweenDates is expecting two date strings in full UTC format like so: yyyy-MM-ddTHH:mm:ss.SSS+0000 My javascript example:
       var date1 = new Date();
       var date2 = new Date();
       date2.setHours(date1.getHours() + 24);
       
       var date1ISO = date1.toISOString();
       var date2ISO = date2.toISOString();
       
       date1ISO = date1ISO.replace("Z", "+0000");
       date2ISO = date2ISO.replace("Z", "+0000");
       
       var events = Ti.Calendar.defaultCalendar.getEventsBetweenDates(date1ISO, date2ISO); 
       
    Works perfectly.
  2. Dan Tamas 2013-08-26

    Hi Sean, thnx for the workaround. I use a module for now but this needs to be fixed.
  3. Braden Powers 2015-01-28

    This is still an issue. Could we get a fix in place for this?
  4. Melissa Chan 2016-02-17

    Has there been any updates in regards to the spelling issue here? This bug is of low priority, but it forces developers to make the fix themselves when they update Titanium/add new developers to their project. Thanks!
  5. Kiley Williams 2016-02-18

    +1 We encountered this last year, and it still is a very serious pain that we need to modify the file in the titanium library folder every time we want to use a new build of the platform. What is the time frame for this fix? It seems to be a simple mispelling as @Melissa said above.
  6. Angel Petkov 2016-02-20

    Changes spelling and did a change so you can pass in Date objects and strings , instead of just strings.
       var date1 = new Date(new Date().getTime() + 3000),
           date2 = new Date(new Date().getTime() + 900000);
           date3 = new Date(new Date().getTime() + 1000000);
           Ti.API.info(date1);
           defCalendar = null;
           
       if (Ti.Calendar.hasCalendarPermissions()) {
           getEventsBetweenDates();
           performCalendarReadFunctions();
       } else {
           Ti.Calendar.requestCalendarPermissions(function(e) {
               if (e.success) {
                   getEventsBetweenDates();
                   performCalendarReadFunctions();
               } else {
                   Ti.API.error(e.error);
                   alert('Access to calendar is not allowed');
               }
           });
       }
       
       function getEventsBetweenDates() {
         defCalendar = Ti.Calendar.defaultCalendar;
       
         var event1 = defCalendar.createEvent({
                 title: 'Sample Event',
                 notes: 'This is a test event which has some values assigned to it.',
                 location: 'Appcelerator Inc',
                 begin: date1,
                 end: date2,
                 availability: Ti.Calendar.AVAILABILITY_FREE,
                 allDay: false,
           });
       
           var event2 = defCalendar.createEvent({
                 title: 'Sample Event',
                 notes: 'This is a test event which has some values assigned to it.',
                 location: 'Appcelerator Inc',
                 begin: date2,
                 end: date3,
                 availability: Ti.Calendar.AVAILABILITY_FREE,
                 allDay: false,
           });
       
         event1.save(Ti.Calendar.SPAN_THISEVENT);
         event2.save(Ti.Calendar.SPAN_THISEVENT);
       }
       
       function performCalendarReadFunctions() {
         // date2.setHours(date1.getHours() + 24);
          
         var date1ISO = date1.toISOString();
         var date2ISO = date2.toISOString();
          
         date1ISO = date1ISO.replace("Z", "+0000");
         date2ISO = date2ISO.replace("Z", "+0000");
          
         var events = defCalendar.getEventsBetweenDates(date1, date2); 
         Ti.API.info(events);
        
         Ti.API.info(events.length);
       }
       
    PR pending: https://github.com/appcelerator/titanium_mobile/pull/7756
  7. Hans Knöchel 2016-02-20

    [~ndustri] [~rborn] Can you validate that the PR is working for your use cases as well? I need to setup some demo dates first to finish CR and FT on this ticket. Thanks guys!
  8. Kiley Williams 2016-02-20

    (y)(y)
  9. Harry Bryant 2016-08-08

    Verified as fixed. Tested On: iPhone 6S (9.3.3) Device Mac OSX El Capitan 10.11.6 Ti SDK: 5.4.0.v20160804185318 Appc Studio: 4.7.0.201607250649 Appc NPM: 4.2.7 App CLI: 5.4.0-40 Xcode 7.3.1 Node v4.4.7 *Closing ticket.*

JSON Source