here are some few conversions needed to have the calendar events “when” objects converted into GAD DateTimeProperty model values.

The first thing we must keep in mind is: the calendar “when” object returns a list to be interacted, and get the calender event start and end time strings.  So, you  should have something like the piece of code below:

query = gdata.calendar.service.CalendarEventQuery(‘default’, ‘private’, ‘full’, text_query)

feed = calendar_service.CalendarQuery(query)
for i, an_event in enumerate(feed.entry):
print ‘\t%s. %s’ % (i, an_event.title.text,)
print ‘\t\t%s. %s’ % (i, an_event.content.text,)
for a_when in an_event.when:
print ‘\t\tStart time: %s’ % (a_when.start_time,)
print ‘\t\tEnd time:   %s’ % (a_when.end_time,)

The start_time and end_time are simple strings in UTC format. Such values looks like something as “2008-05-23T08:30:10.000-03:00″. So you have the date: (2008-05-23), the time (08:30:10.000) and the time zone (-03:00 is one of the Brazilian zone). Once you don´t have a way to enter the seconds, milliseconds and the time zone in a single calendar event, the best thing to do is cut them out. So we will use the slice notation to do that.  Just keep the first 16 characters from the datetime string  [:16], and them proceed with the convertion using the strptime datetime function. This function parses a string input to a datetime object based on a given string format.

Take a look at this simple example:

class DateTime(db.Model):
when = db.DateTimeProperty(auto_now_add=False, required=False)

aDateTime = DateTime()
aDateTime.when = datetime.datetime.strptime(w.start_time[:16],”%Y-%m-%dT%H:%M”)