Mercurial > babel > old > mirror
changeset 257:ea9da47e35bc
Added examples for using `get_timezone_name` to documentation.
author | cmlenz |
---|---|
date | Wed, 15 Aug 2007 13:12:25 +0000 |
parents | 650ef4d82c91 |
children | 5f3534425eab |
files | babel/dates.py doc/dates.txt doc/numbers.txt |
diffstat | 3 files changed, 43 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/babel/dates.py +++ b/babel/dates.py @@ -367,7 +367,7 @@ if dt_or_tzinfo is None or isinstance(dt_or_tzinfo, (int, long)): dt = None tzinfo = UTC - elif isinstance(dt_or_tzinfo, (datetime, time)): + elif isinstance(dt_or_tzinfo, (date, time)): dt = dt_or_tzinfo if dt.tzinfo is not None: tzinfo = dt.tzinfo
--- a/doc/dates.txt +++ b/doc/dates.txt @@ -197,7 +197,7 @@ +----------+--------+--------------------------------------------------------+ -Time-Zone Support +Time-zone Support ================= Many of the verbose time formats include the time-zone, but time-zone @@ -243,6 +243,43 @@ .. _`pytz`: http://pytz.sourceforge.net/ +Localized Time-zone Names +------------------------- + +While the ``Locale`` class provides access to various locale display names +related to time-zones, the process of building a localized name of a time-zone +is actually quite complicated. Babel implements it in separately usable +functions in the ``babel.dates`` module, most importantly the +``get_timezone_name`` function: + +.. code-block:: pycon + + >>> from pytz import timezone + >>> from babel import Locale + >>> from babel.dates import get_timezone_name + + >>> tz = timezone('Europe/Berlin') + >>> get_timezone_name(tz, locale=Locale.parse('pt_PT')) + u'Hor\xe1rio Alemanha' + +You can pass the function either a ``datetime.tzinfo`` object, or a +``datetime.date`` or ``datetime.datetime`` object. If you pass an actual date, +the function will be able to take daylight savings time into account. If you +pass just the time-zone, Babel does not know whether daylight savings time is +in effect, so it uses a generic representation, which is useful for example to +display a list of time-zones to the user. + +.. code-block:: pycon + + >>> from datetime import datetime + + >>> dt = tz.localize(datetime(2007, 8, 15)) + >>> get_timezone_name(dt, locale=Locale.parse('de_DE')) + u'Mitteleurop\xe4ische Sommerzeit' + >>> get_timezone_name(tz, locale=Locale.parse('de_DE')) + u'Deutschland' + + Parsing Dates ============= @@ -251,3 +288,5 @@ .. code-block:: pycon >>> from babel.dates import parse_date, parse_datetime, parse_time + +.. note:: Date/time parsing is not properly implemented yet