views:

413

answers:

3

I have data that is the utc offset and the utc time, given that is it possible to get the users local timezone (mainly to figure if it is dst etc. probably using pytz), similar to the function in php timezone_name_from_abbr ?

For example:

If my epoch time is: 1238720309 I can get the utc time as:

d = datetime.utcfromtimestamp(1238720309) print d + dt.timedelta(0,-28800) #offset for pacific I think 2009-04-02 17:04:41.712143

this is correct except it is pdt right now so it should be: 2009-04-02 18:04:41.712413 I need to the timezone to use in pytz to figure out if it is daylight saving I think?

+3  A: 

Since, in general, there is more than one possible time zone for a given time zone offset, the general answer is "No, not without more information". The more information is typically the location to which the time applies - which country, or state, or city.

Jonathan Leffler
Timezone boundaries are more-or-less random. Technically, they're county-by-county in the US, and don't have to follow state borders. Also, DST varies by locale -- particularly in Arizona and Indiana, other states may also have complex rules.
S.Lott
+1  A: 

No. Time zones are too complicated and there are too many that are X hours from UTC.

http://en.wikipedia.org/wiki/List_of_time_zones

For example, -5 from UTC could be Canada, New York, Cuba, Jamaica, Ecuador, etc.

The equator zones probably don't use DST since their day is roughly 12 hours year long. The south american ones, if they use some form of DST are probably on the opposite schedule of the north american ones because their summer/winter (i.e. short days/long days) schedules are also opposite.