3

I am developing a website where the users can log in with their Facebook credentials.

Now I am facing an issue with Date and Times. My local system uses the "Romance Standard Time" which is different to what Facebook uses.

Where I am locally we use DST and depending on the time of the year we can either be at UTC + 1 or UTC + 2.

My question is, "How can I translate the Facebook times into the format my local system will use, taking into account the occasional change between UTC+1 and UTC+2?"

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Androme
  • 2,399
  • 4
  • 43
  • 82
  • You'll havta calculate that yourself. Although I could be wrong (i don't know that area), What you're thinking is UTC+1 to UTC+2 is probably just a change of time, not an actual timezone. – Tommy Crush Jan 21 '13 at 15:51
  • Edited to emphasize the question and some general clean up. Hope you dont mind! –  Jan 21 '13 at 15:51
  • Tommy Crush, diffrent countries even if they are in the same timezone, can one use DST and another might not! – Androme Jan 21 '13 at 15:54
  • @DoomStone Please clarify, are you dealing with facebook *event* times? And if so, have you already read [this](http://developers.facebook.com/blog/post/2012/08/01/platform-migration--events-timezone-support/) – Matt Johnson-Pint Jan 21 '13 at 16:26
  • @MattJohnson No it is simply just to simplify the registation on my site, so they can auto fill the data in the form. – Androme Jan 21 '13 at 20:43
  • yeah, I don't think you're going to be able to rely on facebook to give you the proper timezone id. Either ask the user, or guess using something like [jsTimeZoneDetect](https://bitbucket.org/pellepim/jstimezonedetect) – Matt Johnson-Pint Jan 21 '13 at 22:18

2 Answers2

3

Per this documentation, the only way for a user to change their timezone is to change their computer's timezone and log out and back in to Facebook. This would lead me to believe that they are simply taking the offset from UTC in JavaScript in the browser and passing it back to the server.

So the value of the timezone field coming back from the Facebook Graph API is probably the offset as of the last time the user logged in.

It's also possible it represents the offset as of the date the user signed up, and that it can't change. I couldn't find any reference in the documentation, so one would have to experiment to be sure.

At either rate, one can't derive the time zone from the offset alone. There are many time zones that have the same offset. For a useful analogy, see my answer on a related subject here.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • Yes i have reached the same conclusion, but i thought i better ask, if some one had found a solution! – Androme Jan 21 '13 at 15:56
  • Try taking your own facebook acount, check the value, change your local computer's clock to a different timezone and log off and back on to facebook. Go check the value from the API again and see if it changed. – Matt Johnson-Pint Jan 21 '13 at 15:57
1

Dealing with Facebook times is difficult. Here is my experience:

  • If you get a 24-character ISO 8601 timestamp back, like 2013-01-17T08:00:00+0000, the offset from UTC is defined. You just need to parse this and convert it to your local offset.
  • If you get a Unix timestamp, like 1358694451, it is in the timezone defined as America/Los_Angeles in PHP.
  • If you get an ISO 8601 timestamp that is 19 characters or fewer, like 2013-01-17 or 2013-01-17T08:00:00 than the time is either relative to the locale of the object with that time, or if the object has no locale, then it is in the America/Los_Angeles timezone.

I'm not a c# developer, but this MSDN article might be of help for converting timezones. http://msdn.microsoft.com/en-us/library/bb397769.aspx

cpilko
  • 11,792
  • 2
  • 31
  • 45