[Zope3-Users] Timezones and zope.i18n.locale

FB fbo2 at gmx.net
Fri Feb 16 02:48:42 EST 2007


Hi,

On Thu, Feb 15, 2007 at 02:46:44PM -0800, Jamu Kakar wrote:
> Hi,
> 
> I'm looking at integrating zope.i18n.locale into my application (so far
> strings are hard-coded in English).  Among the first localization tasks
> I'm taking on is presenting data in the timezone of the current user.
> I've been perusing the code in zope.i18n.locale and I see some mention
> of timezones but nothing that would lead me to believe that dates (in
> UTC) will be auto-converted to the user's timezone when presented with
> formatting methods.

AFAIK there's is no easy way of automatically determining a user's timezone.
The HTTP-Request contains language preference information only but no
timezone preference. However - if you know some clever algorithm which is
i.e. able to tell the time zone from the client's IP, you'll have to write
an adapter providing zope.interface.common.idatetime.ITZInfo adapted from a
IBrowserRequest. Some components (i.e. zc.datetimewidget) will take it into
account when interacting with the user.

To convert a (tz-aware!) datetime-object to the correct timezone, use a method
like that in your view class (not testet):


 zope.interface.common.idatetime.ITZInfo

 [...]

 class MyView(BrowserView):
    [...]
    def getLocalTZ(self,mydatetime):
       tz=ITZInfo(self.request)
       return mydatetime.astimezone(tz)

BTW: Maybe you know that request.locale.dates.getFormatter('dateTime').format(mydatetime)
     shows a I18Nd and L10Nd datetime according to the user's language preference.
     If you can read german, you can find more about that @
     http://zope3.mpg.de/cgi-bin/twiki/view/Zope/LocaliSation .

Regards,

Frank


More information about the Zope3-users mailing list