views:

97

answers:

2

I am currently writing a site that interacts with Facebook and creates events for users. I am using Javascript to submit the event, which is submitting successfully. The problem is, the time that is displayed on Facebook is way off from the time I am submitting.

Here is my code:

var event = {
    start_time: '{{ show_time.start_time|date:'U' }}',
    name: 'Movie Night: ' + '{{ show_time.movie.title }}'
};

FB.api('/me/events', 'post', event, function(response) {
    // Send invites, etc...
});

Yes, we're using some Django in there.

{{ show_time.start_time|date:'U' }} will put in an epoch timestamp. I have also send in an ISO 8601 datetime with the same results. Currently, we have no timezone information in the datetimes. I am not sure if that is causing the problem though, because to test, I had appended -06:00 to the start_time, and it still showed up wrong on Facebook.

What is confusing me is in the docs on Facebook, they show a curl line that supposedly creates an event, and the start_time they send in is an epoch timestamp. In other parts of the same page, they say the start_time must be ISO 8601. I have also read that you need to convert your datetime to Pacific time, then convert to an epoch timestamp, then submit that as the start_time. I just want to know what the correct way is. The Facebook docs seem to be pretty bad at this, so I'm hoping SO can help! Who has actually created an event with Facebook through the Javascript API and had it show up with the correct time on the site? How did you do it?

A: 

First of all, there is a bug on Facebook event timezone management. If you check an Event on the API and on Facebook, you can see different dates. The right date on the API and the wrong date on Facebook, because you add the event by the API. If you created the Event on Facebook, the API will show the wrong date.

If you try any API event call you can see the format used:

"end_time": "2010-03-15T00:30:00+0000"

As you can notice, the date/time format is ISO 8601 and you should use this but, probably, epoch timestamp should work. By looking at the timezone (UTC, +0000) you can guest that you should convert your local date to UTC (+0000) but this is the problem.

The date must be converted to PST/PDT timezone, but keeping the UTC timezone designator (+0000) as Mike Lambert found http://bugs.developers.facebook.net/show_bug.cgi?id=12558

I guess at this point the API is wrong, but predictably wrong, and fixing it would just break other developers. So you could argue it's a documentation bug: http://developers.facebook.com/docs/reference/api/event

It should really say these ISO-formatted UTC times should all be converted to PST/PDT to retrieve the time of the event as entered by the user. (Which is not the UTC/GMT time the event will actually occur.)

Coquevas
I've tried that :( I sent in 2010-10-22T19:30+0000 for the start time, which is the PST/PDT time for the event, with UTC timezone information. It comes back as 2010-10-22T12:30:00+0000.
Gromer
¿What do you get if you add the right date+timezone? ¿and ussing PST/PDT date AND timezone? ¿and adding the event on Facebook? PS: Sorry for the delay, I was out for the weekend.
Coquevas
A: 

@Coquevas as per your last comment, have you tried putting for example "+0800" if you're for example in GMT+8?

pageman
No, it's really a bug filled and accepted, but workaroundable: http://bugs.developers.facebook.net/show_bug.cgi?id=7210
Coquevas