Hi all,

since I asked about timezone corrections and didn't get any info, as well as 
others seem to have the same problem, here's what solved the issue for me:

install pytz  (easy_install pytz)
install babel (easy_install babel - docs can be found at 
http://babel.edgewall.org)

I added a stdvars.py in my project directory containing

import turbogears.i18n as i18n
from babel.dates import format_datetime

def add_custom_stdvars(vars):
    vars.update({"format_datetime": format_datetime})
    vars.update({"locale": i18n.get_locale()})
    return vars

turbogears.view.variable_providers.append(add_custom_stdvars)


You'd need to get the timezone for the client from somewhere. In my case I get 
it from a database table where the user can set up his timezone, i.e. 
US/Pacific. You might do a IP address trace or something the like.
The "getSettings()" method in the snippet below returns a db object which has 
a user-defined setting for the timezone - so this is where you'd need to 
adapt it.

Now in the controller I just add the user's timezone to the return dict, like

on top:
from pytz import timezone

        settings=getSettings()
        res['timezone']=timezone(settings.timezone)
        return res

And finally in the template (in my case Genshi)

${tg.format_datetime(<your_datetime_here>,format='medium',tzinfo=timezone,locale=tg.locale)}

wherever you need the formatted datetime.
I added the locale (which wouldn't be necessary for the timezone correct 
display) because then not only the timezone is correct, but also the date 
format, i.e. 1.7.2007 22:23:15 when the locale is de_DE and
Jan 7 2007 10:23:15 pm when the locale is en_US
The locale is sucked from the browser settings, so if the user set up his 
computer correctly it should come out right automatically.

Hope this helps someone.

        Uwe

--
Open Source Solutions 4U, LLC   1618 Kelly St
Phone:  +1 707 568 3056         Santa Rosa, CA 95401
Cell:   +1 650 302 2405         United States
Fax:    +1 707 568 6416

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to