Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2528] Creating an allday event on Android shifts the day back by one on device

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2014-07-28T17:28:43.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterStefan Schüller
AssigneeMauro Parra-Miranda
Created2013-08-30T09:39:35.000+0000
Updated2016-03-08T07:41:35.000+0000

Description

When creating an allday event the day is not entered into the devices calendar on the correct day. When setting allday to false the event is added at the correct time points. Test Case:
var t = ('2013-08-04 00:00:00').split(/[- :]/);
var start = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);     

var t = ('2013-08-04 23:59:59').split(/[- :]/);
var end = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);       

Ti.API.info('start: '+start);     
Ti.API.info('end: '+end);             

var CALENDAR_TO_USE = 1;
var defCalendar = Ti.Calendar.getCalendarById(CALENDAR_TO_USE);             

defCalendar.createEvent({
    title: 'test',
    notes: 'notes',
    location: 'Some address',
    begin: start,
    end: end,
    allDay: true
});
Console will print:
start: Sun Aug 04 2013 00:00:00 GMT+0200 (CEST)
end: Sun Aug 04 2013 23:59:59 GMT+0200 (CEST)
But the event is added to August 3rd on the device.

Attachments

FileDateSize
device-2013-08-30-113837.png2013-08-30T09:39:35.000+0000680488
device-2013-09-19-165812.png2013-09-19T14:59:04.000+000096515

Comments

  1. Motiur Rahman 2013-09-18

    Hi Stefan Schüller, Your code is incomplete could you provide runnable code so that i can past into the app.js file and reproduce this issue. And you can also follow [this link](http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.Calendar) Thanks,
  2. Stefan Schüller 2013-09-18

    The code I posted is exactly what I have in my app.js. The app will show the splash and do nothing other than this so you need to force close it. I found the Problem in another app but I can not post it, this is why I create this app as a test. Exact Process:

    Start monitor from android SDK

    Connect Android phone

    In Titanium Run on Android Device

    App launches with splash screen

    Observe log output on monitor

    Close app and check calendar on device.

    Thanks, Stefan
  3. Stefan Schüller 2013-09-18

    Hi Motiur, Here is a version with a window and a button. It will print what it wanted to do into the two labels. When you check the phone calendar you will see it added it to the wrong day.
       
       var w = Titanium.UI.createWindow({backgroundColor:'#000'});
       
       var view = Titanium.UI.createView({});
       
       var button = Titanium.UI.createButton({
         height: 100,
         width: 300,
         top: '20%',
         title: 'add event'
       });
       
       var label1 = Titanium.UI.createLabel({
       	top: '40%',
       	color: '#fff'
       });
       var label2 = Titanium.UI.createLabel({
       	top: '42%',
       	color: '#fff'
       });
       
       button.addEventListener('click',function(e)
       {
       	// If no time is defined set all day
       	var t = ('2013-08-04 00:00:00').split(/[- :]/);
       	var start = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);     
       	
       	var t = ('2013-08-04 23:59:59').split(/[- :]/);
       	var end = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);       
       	
       	Ti.API.info('start: '+start);     
       	Ti.API.info('end: '+end);             
       	
       	label1.text = 'start: '+start;
       	label2.text = 'end: '+end;
       	
       	var CALENDAR_TO_USE = 1;
       	var defCalendar = Ti.Calendar.getCalendarById(CALENDAR_TO_USE);             
       	
       	defCalendar.createEvent({
       	    title: 'test',
       	    notes: 'notes',
       	    location: 'Some address',
       	    begin: start,
       	    end: end,
       	    allDay: true
       	});
       });
       
       view.add(button);
       view.add(label1);
       view.add(label2);
       w.add(view);
       w.open();
       
    Let me know if you need anything else. Thanks, Stefan
  4. Motiur Rahman 2013-09-18

    Hi Stefan Schüller, I have tested your code, you just split the date and time then show it in console and label and it occurs perfectly but you said that allday event the day is not entered into the devices calendar on the correct day, i don't reproduce this issue. You can follow [this link](http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Calendar) and try to solve it. Then know me. Thanks,
  5. Stefan Schüller 2013-09-19

    Hi Motiur, I still doesn't work for me (even on the latest SDK 3.1.3). I adjusted my test code to use the almost exact same code as the example in the documentation:
       var w = Titanium.UI.createWindow({backgroundColor:'#000'});
        
       var view = Titanium.UI.createView({});
        
       var button = Titanium.UI.createButton({
         height: 100,
         width: 300,
         top: '20%',
         title: 'add event'
       });
        
       var label1 = Titanium.UI.createLabel({
           top: '40%',
           color: '#fff'
       });
       var label2 = Titanium.UI.createLabel({
           top: '42%',
           color: '#fff'
       });
        
       button.addEventListener('click',function(e)
       {
       	
       	var CALENDAR_TO_USE = 1;
       	var calendar = Ti.Calendar.getCalendarById(CALENDAR_TO_USE);
       	
       	// Create the event
       	var eventBegins = new Date(2013, 07, 04, 00, 00, 00);
       	var eventEnds = new Date(2013, 07, 04, 23, 59, 59);
       	
       	Ti.API.info('start: '+eventBegins);     
       	Ti.API.info('end: '+eventEnds);             
            
       	label1.text = 'start: '+eventBegins;
       	label2.text = 'end: '+eventEnds;
       	
       	var details = {
       	    title: 'Do some stuff',
       	    description: "I'm going to do some stuff at this time.",
       	    begin: eventBegins,
       	    end: eventEnds,
       	    allDay: true
       	};
       	
       	var event = calendar.createEvent(details);	 
       
       });
        
       view.add(button);
       view.add(label1);
       view.add(label2);
       w.add(view);
       w.open();
       
    It is still off by one day. The event should be added to August 4th but is added to August 3rd on the devices calendar. This is on a Samsung Galaxy S3 (GT-I9300), Android 4.1.2.
  6. Shak Hossain 2013-12-11

    @Stefan - Thanks for sending us your code. We will test it ASAP and post an update for you.
  7. Eric Wieber 2013-12-11

    Hi Stefan, I was unable to reproduce this issue on our Galaxy S2 and Galaxy S3 devices. This could be a timezone issue. According to the documentation for Date(): "The JavaScript Date object provides uniform behavior across platforms. The time value can be passed between systems to represent the same moment in time and if used to create a local date object, will reflect the local equivalent of the time. The JavaScript Date object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed." It looks like your device is in the CEST GMT+0200 timezone, could you please verify what timezone your device is set to? You could also consider setting the calendar event to start several hours later in the day to see if the event is then on the correct day, as a test. If that is the case, you may need to modify your code to account for different timezones.
  8. Stefan Schüller 2014-02-06

    The timezone on the device is GMT +2. Setting eventBegins hours to 02 works but I don't understand why setting a non all day event works correctly placing the item at the correct time and a fullday event does not. Adding a non allday event correctly I need to do this:
           var eventBegins = new Date(2013, 07, 04, 12, 00, 00);
           var eventEnds = new Date(2013, 07, 04, 13, 00, 00);
           var details = {
               title: 'Do some stuff',
               description: "I'm going to do some stuff at this time.",
               begin: eventBegins,
               end: eventEnds,
               allDay: false
           };
       
    For an allday event I need to do this (makes no sense that the timezone is checked here but not above):
           var eventBegins = new Date(2013, 07, 04, 02, 00, 00);
           var eventEnds = new Date(2013, 07, 04, 23, 59, 59);
           var details = {
               title: 'Do some stuff',
               description: "I'm going to do some stuff at this time.",
               begin: eventBegins,
               end: eventEnds,
               allDay: true
           };
       
  9. Stefan Schüller 2014-02-07

    Just FYI, in iOS I do not need to account for the GMT offset. This code works fine on an iOS device with GMT +2 but does not work on an Android device with GMT +2
       var w = Titanium.UI.createWindow({backgroundColor:'#000'});
        
       var view = Titanium.UI.createView({});
        
       var button = Titanium.UI.createButton({
         height: 100,
         width: 300,
         top: '20%',
         title: 'add event'
       });
        
       var label1 = Titanium.UI.createLabel({
           top: '40%',
           color: '#fff'
       });
       var label2 = Titanium.UI.createLabel({
           top: '42%',
           color: '#fff'
       });
        
       
       function addEvent(){
       
       	if (Ti.Platform.osname === 'android') {
       		var CALENDAR_TO_USE = 1;
       		var calendar = Ti.Calendar.getCalendarById(CALENDAR_TO_USE);
       	} else {
       		var calendar = Ti.Calendar.defaultCalendar;			
       	}
       
       	// Create the event
       	var eventBegins = new Date(2014, 01, 20, 00, 00, 00);
       	var eventEnds = new Date(2014, 01, 20, 23, 59, 59);
       	
           Ti.API.info('start: '+eventBegins);     
           Ti.API.info('end: '+eventEnds);             
            
           label1.text = 'start: '+eventBegins;
           label2.text = 'end: '+eventEnds;
       	
       	var details = {
       	    title: 'Do some stuff',
       	    description: "I'm going to do some stuff at this time.",
       	    begin: eventBegins,
       	    end: eventEnds,
       	    allDay: true
       	};
       	
       	var event = calendar.createEvent(details);	
       	
       	if (Ti.Platform.osname === 'iphone') {
       		event.save(Ti.Calendar.SPAN_THISEVENT);
       	}
       }
        
         
       button.addEventListener('click',function(e)
       {
       	if (Ti.Platform.osname === 'android') {
       		addEvent();
       	} else {
       		if(Ti.Calendar.eventsAuthorization == Ti.Calendar.AUTHORIZATION_AUTHORIZED) {
       			addEvent();
       		} else {
       		    Ti.Calendar.requestEventsAuthorization(function(e){
       				addEvent();
       		    });								
       		}
       	}
       });
        
       view.add(button);
       view.add(label1);
       view.add(label2);
       w.add(view);
       w.open();
       
  10. Brandon Neil 2014-04-03

    I have also run into this issue and setting all day events to a day past to account for our -5:00 or -06:00 timezone offset. This only occurs on Android on allday events that are longer than one day. My only major difference between the code above is I'm using the bundled moment.js that is included with alloy to create the dates. Ti 3.2.2.GA Nexus 7 - 4.4.2 Samsung Galaxy S3 - 4.3 Moto Droid Razor HD - 4.1.2 Moto Droid Razr - 2.3.7
  11. Mauro Parra-Miranda 2014-07-28

    Fixed in 3.3.0.GA. Tested with Moto X with Android 4.4.2.

JSON Source