1

When I use the Facebook Profile API, the GMT offset I currently get is -7 when in San Francisco.

However, San Francisco is -8. So I believe this is due to a DST off-set.

But how do I get the offset and, therefore, the correct time zone if I am given an inaccurate one from Facebook?

E.g. I cannot use the offset to convert to a timezone to then determine if it is DST because I believe some time zones do not respect DST. So my original solution would fail:

  • get time zone from offset
  • get period for the timezone
  • determine if period is DST or not
  • if DST, change the offset, and then determine the time zone again.

Is there a cleaner way to get the time zone using ruby when given the GMT offset that incorporates DST?

Satchel
  • 16,414
  • 23
  • 106
  • 192
  • 2
    You're correct that -7 (PDT) is the current offset for SF. That response from FB is correct for that particular day, time, and location. There's normally no need to do more. That other time zones do not use DST is irrelevant to the local time in San Francisco. What are you doing that you might need to account for DST? – Schwern Aug 08 '17 at 00:04
  • Hi. Your questions are addressed in the duplicate linked, though that person asked about PHP and you asked about Ruby, the problem is otherwise identical. Basically, you need a time zone and facebook only gives you an offset. Your point #1 is not something that is possible. Sorry. – Matt Johnson-Pint Aug 08 '17 at 00:19
  • I want to store the correct time zone. When I used acri_support timezone -7 it gives me Arizona. – Satchel Aug 08 '17 at 13:18
  • I am storing the time zone in a database so that I know a particular time the user wants a reminder. – Satchel Aug 08 '17 at 13:19
  • There are more than 1 timezone that uses -7 offset: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones - actually, that's valid for all offsets: one timezone can have more than 1 offset (it can change during Daylight Saving Time, for example), and the same offset can be used by more than 1 timezone. It's not a 1 to 1 mapping, so you can't get a timezone from an offset (what some API's do is define some "defaults", but those will always be error-prone). –  Aug 08 '17 at 15:57

0 Answers0