[Zope3-Users] obtaining time zone from http request

Gary Poster gary at zope.com
Sun Aug 28 23:30:07 EDT 2005

On Aug 28, 2005, at 10:59 PM, Stephan Richter wrote:

> On Sunday 28 August 2005 21:10, Alen Stanisic wrote:
>> what's the best way to obtain timezone from request object. I tried
>> tz = pytz.timezone(ITZInfo(self.request))
>> but the adaptation failed.
> Getting a single time zone from the request is not sensible.  
> Requests know
> only about the locale. But the locale can be applicable in multiple
> timezones. However, the locale usually knows about the timezones  
> that are
> part of the locale. The object ``request.locale.dates.timezones`` is a
> mapping from timezone names (in the ICU format) to
> ``zope.i18n.interfaces.locales.ITimeZone`` objects.

Other excitement: the timezone names in the ICU database do not all  
correspond to the timezones in the olson timezone database (upon  
which pytz is based).

Generally, you want to let users choose their timezone.  Guessing can  
work like this though (Py 2.4):

ALL_TIMEZONES = frozenset(pytz.all_timezones)

for t in self.request.locale.dates.timezones.keys():
     if t in ALL_TIMEZONES:
         return pytz.timezone(t)

Maybe the ICU timezone object has alternate names to try in Olson; I  

> Unfortunately the version of the ICU data we are using does not  
> have very good
> timezone support. At some point we need to switch to a newer  
> version, which
> is much better with timezones as far as I remember.

I looked around at this a month or two ago and didn't see much  
improvements, actually.  Maybe I'm wrong.


More information about the Zope3-users mailing list