Given a local timestamp and a UTC timestamp, is it possible to determine the timezone and whether DST is in effect?
Try taking a look at http://docs.python.org/library/datetime.html#datetime.datetime for built-in support for dates, times, and timezones.
If you need a more powerful library, peek at the suggestions here: http://stackoverflow.com/questions/1442264/full-featured-date-and-time-library
If your "UTC timestamp" is a float (int would suffice) of "seconds from the epoch", and your "local timestamp" is some weird version of it shifted into your local time coordinates (there is no "epoch" except the UTC one), module time in the standard Python library suffices.
As these docs show, given "seconds from the epoch", gmtime
translates that into a 9-items tuple in UTC, localtime
into a 9-items tuple in local time; to go the other way around, calendar.timegm
(UTC 9-items tuple to UTC timestamp) and mktime
(local time 9-items tuple to UTC timestamp). You'll note there's no such thing as a "local timestamp" (only local time 9-items tuples aka struct_time
instances), simply because no such concept exists.
But, if I understand correctly what you mean by "local timestamp", then translating it to a struct time "as if" it was a real timestamp, and then back into local time, will give the offset you seek (in seconds). As for DST, a bit telling whether it's on is the 9th item of the tuples we've been mentioning.
For example, using the "local timestamp" only:
>>> loct
1282453595
>>> time.mktime(time.gmtime(loct)) - loct
28800.0
>>> _ / 3600
8.0
>>>
This says I'm 8 hours west of UTC. And:
>>> time.localtime(loct)[-1]
1
this says that it is with DST in effect.