facebook API returning incorrect event date times

Aug 24, 2007 at 3:00 PM
Hey everyone,

I have been reading this forum for the past couple weeks and it has been a tremendous help thus far, so i hope someone can make more sense out of this strange behavior because i have yet to be able to.

I have been working on an application for the past few weeks that allows users to view and manage their events and lately came across an interesting data issue when I noticed all of my event times pulled through the API were wrong.

background:
-dev environment C#.net
-web application
-using .NET toolkit version 1.2

The problem is that the start dates and end dates that I pull from Facebook are off by 3 hours from the dates I see on the web interface upon logging in to facebook.com. I am currently located in the EST (eastern US time zone) and have checked the clocks on my dev computer and server to ensure that they are all set to proper time zones.

EXAMPLE:
-Title: A Black Tie 21st Event
-Start Date (facebook.com): 8/3/07 6:00pm
-End Date (facebook.com): 8/5/07 12:00pm
-Start Date (my app): 8/3/07 9:00pm
-End Date (my app): 8/5/07 3:00pm

I am aware that Facebook uses the seconds since epoch format to store dates for these events and as an additional test have used the api test console on the facebook.com site to retrieve the start date and end dates for these events. To convert the times from the test console to standard date/time format i used the website http://www.epochconverter.com/ and entered the start and end dates for various events. The results from this test using the same event as above are below:

-start date (epoch converter) 8/3/07 9:00pm
-end date (epoch converter) 8/5/07 3:00 pm

This is interesting because it demonstrates that the issue cannot be limited to my application or the microsoft development toolkit that i am using to retrieve and convert the data. Therefore this is either a bug in the way that facebook stores their event times or there is something I am missing entirely when trying to retrieve these dates.

My initial thought was that I needed to compensate for three hours of time zone difference since Facebook is located in California, however the +3 hour time zone difference would put these times somewhere in the middle of the Atlantic not in California. I have tried a few different methods to calculate the data and understand what sort of date processing is going on inside the Facebook servers but have yet to reach any logical conclusion as to how these dates are being processed and displayed correctly on the facebook.com events section.

For the meantime I have added in some additional logic in my app to correct this error by subtracting three hours from all event times before they are used, however any insight into this problem will be much appreciated

Thank you,
Costa
Coordinator
Sep 12, 2007 at 3:53 AM
Did you post this with Facebook to see what they say?
Oct 25, 2007 at 7:24 PM
Edited Oct 25, 2007 at 7:25 PM
I've noticed that my times are off as well, although I'm not using Facebook.Net to convert them, but a function:

public System.DateTime ConvertFBDateTime(object FBDateTime)
{
return new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc).AddSeconds(FBDateTime);
}

This returns a datetime value that is exactly 8 hours later than it should be.
Maybe the Facebook time of 0000000000 or 1/1/1970 12:00:00 AM is GMT?
Dave
Developer
Oct 25, 2007 at 9:58 PM
Edited Oct 25, 2007 at 10:00 PM
From doing a bit of experimentation, here's what I think the Facebook process seems to be (at least for events):
  • Take the start/end time as input by the user and as displayed on Facebook
  • Assume that it is in Pacific Time (Standard or Daylight Savings, depending on the date of the event), and convert the time to UTC
  • Convert that UTC time into UNIX epoch time, and store it

I'm working on a fix for the toolkit which will do this process in reverse, although I'm getting a little hung up on determining when it is or is not Daylight Savings Time in the Pacific time zone, especially with the edge cases when the event is right between those two parts of the year. I may just punt on that for now and make sure it at least works in the majority of cases.
Sep 2, 2008 at 3:15 AM
Hello,

I am just wondering if there has been any updates regarding this conversion of time? Its been awhile since anyone has posted anything. I too am stuck with trying to convert the facebook time into my local time. However I came across this which seems to work for me. I just want to make sure that its no fluke. It has worked with every single event that I have created.

This is what I have done:

timeZoneInfo.ConvertTime(new DateTime(1970,1,1).AddSeconds(fbTime),TimeZoneInfo.Utc,TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"))

Some explaination:
In the Facebook documentation as you have prolly known says:

"Note that the start_time and end_time returned are the times which were input by the event creator, converted to UTC after assuming that they were in Pacific time (Daylight Savings or Standard, depending on the date of the event), then converted into Unix epoch time."

Keeping this in mind, I convert fbTime from epoch into a normal datetime that should be in UTC since epoch time is that format. Assuming that I am understanding what the documentation is saying, I believe that the actual event datetime is in Pacific time. So we convert the normal datetime from UTC to Pacific time.

Can someone please verify if it works? Thanks
Sep 2, 2008 at 3:15 AM
Edited Sep 2, 2008 at 3:16 AM
Made a double post...so i edited it...sorry...