Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1484] Adding Event to Android calendar has wrong timezone

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2015-07-08T15:47:59.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsTCSupportTriage, android
ReporterStefan Schüller
AssigneeRadamantis Torres-Lechuga
Created2014-12-04T08:04:43.000+0000
Updated2016-03-08T07:37:55.000+0000

Description

Line 204: in EventProxy.java (https://github.com/appcelerator/titanium_mobile/blob/58198c641d77e17d156431666e80bae732b5c130/android/modules/calendar/src/java/ti/modules/titanium/calendar/EventProxy.java#L204)
eventValues.put(Events.EVENT_TIMEZONE, new Date().toString());
Appears to be incorrect. The JavaScript method toString on a Date object will produce an output like so "Thu Dec 04 2014 08:47:02 GMT+0100 (CET)" while the Java string Events.EVENT_TIMEZONE needs to be in the format of "GMT +01:00" (http://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html) The result is the following code will not work correctly. The event is added incorrectly which is however only visible in certain Calendars such as the s-planner. The device is set to CET. (See screenshots)

Test Code

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'
});

// events
var events = [
	{
		title: "Event has ümlääüts",
		description: "Event 1 stuff müröälad",
		start: new Date(2014, 12, 4, 17, 0, 0),
		end: new Date(2014, 12, 4, 18, 0, 0),
		allday: false
	}
];


function addEvent(data) {

    var calendar;

	if (Ti.Platform.osname === 'android') {
		calendar = Ti.Calendar.getCalendarById(1);
	} else {
		calendar = Ti.Calendar.defaultCalendar;
	}

    console.log('start: '+data.start);
    console.log('end: '+data.end);

	// Create the event	
	var details = {
	    title: data.title,
	    description: data.description,
	    begin: data.start,
	    end: data.end,
	    allDay: data.allday
	};
	
	var event = calendar.createEvent(details);	
	
	if (Ti.Platform.osname === 'iphone') {
		event.save(Ti.Calendar.SPAN_THISEVENT);
	}
}

function addEvents(events) {
	for(var i in events) {
		addEvent(events[i]);
	}	
} 
  
button.addEventListener('click',function(e)
{
	if (Ti.Platform.osname === 'android') {
		addEvents(events);
	} else {
		if(Ti.Calendar.eventsAuthorization == Ti.Calendar.AUTHORIZATION_AUTHORIZED) {
			addEvents(events);
		} else {
		    Ti.Calendar.requestEventsAuthorization(function(e){
				addEvents(events);
		    });								
		}
	}
});
 
view.add(button);
w.add(view);
w.open();

Attachments

FileDateSize
Screenshot_2014-12-04-08-58-29.png2014-12-04T08:04:43.000+0000338012
Screenshot_2014-12-04-08-59-01.png2014-12-04T08:04:43.000+0000114264
Screenshot_2014-12-04-09-02-13.png2014-12-04T08:04:43.000+000070545

Comments

No comments

JSON Source